Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Custom Model with Tensorflow 2.1

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?

like image 341
Ivar Eriksson Avatar asked Mar 04 '20 16:03

Ivar Eriksson


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.

like image 192
Pirmin Rehm Avatar answered Nov 05 '22 01:11

Pirmin Rehm