I am trying to import a simple GRU tensorflow model into Matlab, but something is not working properly.
The tensorflow model in Python is given by the following function.
def create_model(nodes1, nodes2, history, BATCH_SIZE):
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.GRU(nodes1,
return_sequences=True,
stateful=True,
batch_input_shape=(BATCH_SIZE,history,len(features))))
model.add(tf.keras.layers.GRU(nodes2))
model.add(tf.keras.layers.Dense(horizon))
model.compile(
optimizer=tf.keras.optimizers.Adam(clipvalue=2.0),
loss='mse',
metrics=['mean_absolute_error', 'mean_squared_error'])
return model
Using
importKerasNetwork('model.h5')
does not work. The error I get is.
Warning: Unable to import layer. Keras layer 'GRU' with the specified settings is not supported. The problem was: Recurrent biases for GRU layers are not supported.
Error using nnet.internal.cnn.keras.importKerasNetwork (line 31)
Unable to import network because some network layers are not supported. To import layers and weights, call importKerasLayers with 'ImportWeights' set to true.
Error in importKerasNetwork (line 91)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
Using
importKerasLayers('model.h5','ImportWeights',true)
yields the following warnings:
Warning: Unable to import layer.
Keras layer 'GRU' with the specified settings is not supported. The problem was: Recurrent biases for GRU layers are not supported.
Warning: Unable to import layer.
Keras layer 'GRU' with the specified settings is not supported. The problem was: Recurrent biases for GRU layers are not supported.
Warning: Unable to import some Keras layers, because they are not supported by the Deep Learning Toolbox. They have been replaced by placeholder layers. To find these layers, call the function `findPlaceholderLayers` on the returned object.
As a result the two GRU layers are replaced by placeholders. I do not understand what recurrent bias is, as I have not specified anything like this anywhere nor does this setting exist in the model's configuration.
I then tried to import the configuration and weights seperately, but I get the following error when calling
importKerasNetwork('arch.json',"WeightFile",'weights.h5')
Error using nnet.internal.cnn.keras.importKerasNetwork (line 20)
Error reading Keras model_config from file 'arch.json'. The error message was: 'Dot indexing is not supported for variables of this type.''
Error in importKerasNetwork (line 91)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
So what exactly are reccurent biases and is there a way to solve the dot indexing error? Is there an easy way to directly import the Keras model?
Thanks in advance.
Using Tensorflow 2 and Matlab 2020a
0 Comments
Sign in to comment.