I want to upload a CNN keras model saved from an R session with save_model_hdf5(model, "model.h5") in a Python session with load_model('model.h5')
I am able to load in R a saved model in Python but when I load an R model in Python I am getting this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//lib/python3.6/site-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "//lib/python3.6/site-packages/keras/engine/saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "//lib/python3.6/site-packages/keras/engine/saving.py", line 274, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "//lib/python3.6/site-packages/keras/engine/saving.py", line 627, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "//lib/python3.6/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "//lib/python3.6/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "//lib/python3.6/site-packages/keras/engine/sequential.py", line 302, in from_config
model.add(layer)
File "//lib/python3.6/site-packages/keras/engine/sequential.py", line 182, in add
output_tensor = layer(self.outputs[0])
File "//lib/python3.6/site-packages/keras/engine/base_layer.py", line 463, in __call__
self.build(unpack_singleton(input_shapes))
File "//lib/python3.6/site-packages/keras/layers/normalization.py", line 94, in build
dim = input_shape[self.axis]
TypeError: tuple indices must be integers or slices, not list
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/9d81938d-ac31-4e6a-9b71-41054954a653%40googlegroups.com.
Which version of Keras is this?
To unsubscribe from this group and stop receiving emails from it, send an email to keras...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/9d81938d-ac31-4e6a-9b71-41054954a653%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/a7dd45de-bf97-4709-a50e-03d98e303a70%40googlegroups.com.
I updated tensorflow version:
Keras version in R: keras_2.2.5.0 tensorflow_2.0.0
Keras version in Python: keras_2.3.1 tensorflow_2.1.0
I am getting an other error :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.6/site-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "/lib/python3.6/site-packages/keras/engine/saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "/lib/python3.6/site-packages/keras/engine/saving.py", line 274, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/lib/python3.6/site-packages/keras/engine/saving.py", line 627, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/lib/python3.6/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/lib/python3.6/site-packages/keras/engine/sequential.py", line 301, in from_config
custom_objects=custom_objects)
File "/lib/python3.6/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 149, in deserialize_keras_object
return cls.from_config(config['config'])
File "/lib/python3.6/site-packages/keras/engine/base_layer.py", line 1179, in from_config
return cls(**config)
File "/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/lib/python3.6/site-packages/keras/layers/convolutional.py", line 353, in __init__
**kwargs)
File "/lib/python3.6/site-packages/keras/layers/convolutional.py", line 117, in __init__
self.kernel_initializer = initializers.get(kernel_initializer)
File "/lib/python3.6/site-packages/keras/initializers.py", line 515, in get
return deserialize(identifier)
File "/lib/python3.6/site-packages/keras/initializers.py", line 510, in deserialize
printable_module_name='initializer')
File "/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 149, in deserialize_keras_object
return cls.from_config(config['config'])
File "/lib/python3.6/site-packages/keras/initializers.py", line 30, in from_config
return cls(**config)
File "/lib/python3.6/site-packages/keras/initializers.py", line 204, in __init__
'but got', distribution)
ValueError: ('Invalid `distribution` argument: expected one of {"normal", "uniform"} but got', 'truncated_normal')
Try Tensorflow 2.x in Python. This may be a version discrepancy.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/a7dd45de-bf97-4709-a50e-03d98e303a70%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/99e332e7-642b-40a0-a591-85087892de65%40googlegroups.com.
Thank
you for your help,
I tried
to use Tensorflow 2.1 to identify if the problem comes from the
version, but it does not contain get_session function (even
tf.compat.v1.Session() didn’t solve the problem).
So, I downgraded Tensorflow version to 1.14
I didn’t find the ‘read-only’ argument in load_model (load_model_weights_hdf5(object, filepath, by_name = FALSE, skip_mismatch = FALSE, reshape = FALSE))
When using load_model_weights_hdf5('my_weights.h5') in R I am getting this error :
Erreur : $ operator is invalid for atomic vectors
Best,
Khawla
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/4b190f9e-7f4a-454c-992b-7e883f33661a%40googlegroups.com.