I'm trying to load a model that I trained and saved using Tensorflow & Keras, but it's given me an error.
Python version: 3.6.6
Tensorflow version: 1.11.0
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/engine/saving.py", line 230, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/engine/saving.py", line 310, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize
printable_module_name='layer')
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/utils/generic_utils.py", line 173, in deserialize_keras_object
list(custom_objects.items())))
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/engine/sequential.py", line 339, in from_config
custom_objects=custom_objects)
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize
printable_module_name='layer')
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/utils/generic_utils.py", line 175, in deserialize_keras_object
return cls.from_config(config['config'])
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/engine/base_layer.py", line 1617, in from_config
return cls(**config)
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/layers/advanced_activations.py", line 310, in __init__
if max_value is not None and max_value < 0.:
TypeError: '<' not supported between instances of 'dict' and 'float'
I've also tried just saving the weights instead of the whole model, but that doesn't seem more successful:
Traceback (most recent call last): File "predict_from_NN.py", line 44, in
model.load_weights('/home/me/Data/Out/finished_model_2_weights.hdf5.index')
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/keras/engine/network.py", line 1526, in load_weights
checkpointable_utils.streaming_restore(status=status, session=session)
File "/packages/tensorflow/1.11.0/Python-3.6.6/tensorflow/python/training/checkpointable/util.py", line 880, in streaming_restore
"Streaming restore not supported from name-based checkpoints. File a "
NotImplementedError: Streaming restore not supported from name-based checkpoints. File a feature request if this limitation bothers you.
Although I'm not exactly sure why/how I'm doing a 'streaming restore', and google is not very useful in both cases.
In case it helps, here's the code for my model:
from tensorflow.python.keras.layers import Conv2D, MaxPooling2D, ReLU
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Flatten, Activation, Dense
def cnn_model(img_rows, img_cols, img_channels):
model = Sequential()
model.add(Conv2D(64, (3, 3),activation='linear',kernel_initializer='he_uniform',
input_shape=(img_rows, img_cols, img_channels)))
model.add(ReLU()) # add an advanced activation
model.add(MaxPooling2D(pool_size=(5, 5)))
model.add(Conv2D(32, (3, 3),activation='linear',kernel_initializer='he_uniform'))
model.add(ReLU()) # add an advanced activation
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Conv2D(16, (3, 3),activation='linear',kernel_initializer='he_uniform'))
model.add(ReLU()) # add an advanced activation
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Flatten())
model.add(Dense(1024))
model.add(Dense(1024))
model.add(ReLU()) # add an advanced activation
model.add(Dense(4))
model.add(Activation('softmax'))
return model
And I save my model like this:
model.save(os.path.join(output_folder, model_name + '_GPU.hdf5'))
And try to load it like this:
from tensorflow.python.keras.models import load_model
model = load_model(model_file)