Loading Custom Model with Tensorflow 2.1

Viewed 2635

I have made my own class subclassing tf.keras.Model and am trying to save and load a trained instance of it. I'm trying to follow this tutorial but every time I go to load the saved model I get the same error message: TypeError: __init__() got an unexpected keyword argument 'reduction'. I've tried adding that keyword argument to my class but it changes nothing. Any ideas?

1 Answers

I had the same problem for Tensorflow 1.14 and solved it by adding compile=False to the load function:

new_model = tf.keras.models.load_model('saved_model/my_model', compile=False)

Even with compile=False it is possible to run the model.predict() function.

The solution originates from this Tensorflow issue.

Related