GRU load model error, ValueError: GRU(reset_after=False) is not compatible with GRU(reset_after=True)

Viewed 2151

I am new to ML frameworks and also python. I got the source code for a keras-tensorflow project from https://github.com/xiaochus/TrafficFlowPrediction and Also I installed All CUDA and Cudnn right versions. but after loading gru model it raise an error :

ValueError: GRU(reset_after=False) is not compatible with GRU(reset_after=True).

can anyone help me please? thanks. it seems there is an overloading for this function with options. should I add some options like reset_after to enable/disable it? I am just guessing.

lstm = load_model('TrafficFlowPrediction/model/lstm.h5')
#error in gru model load
gru = load_model('TrafficFlowPrediction/model/gru.h5')
2 Answers

I faced the same issue and the solution above did not work for me. This is why I am adding this here.

I had a TF1.x saved model containing GRU layers. I wanted to convert my code in TF2.X so I had the same issue above.

I fixed the problem by the following code

tf.compat.v1.disable_v2_behavior() # model trained in tf1
model = tf.compat.v1.keras.models.load_model('models/model.h5')

I solved it by changing this part of creating model

model.add(GRU(units[1], input_shape=(units[0], 1), return_sequences=True))

model.add(GRU(units[1], input_shape=(units[0], 1), return_sequences=True, reset_after=True))

Related