When converting a .h5 model with custom layers to json, it's common to have the error
...File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/converter.py", line 133, in dispatch_keras_h5_to_tfjs_graph_model_conversionmodel = tf.keras.models.load_model(h5_path, compile=False)...ValueError: Unknown layer: LayerName
(using LayerName as a general name for the custom layer), which can be fixed by changing in converter.py the line 133 from
model = tf.keras.models.load_model(h5_path, compile=False)
to
custom_objects_dict = {'customLayer': library.customLayer}model = tf.keras.models.load_model(h5_path, compile=False, custom_objects=custom_objects_dict)
I understand that not all Custom Layers can be converted, but this could either be done automatically for the one which can, and only rise an error if it isn't supported; or it could be added an optional argument for passing custom layers .
Code to reproduce the bug / link to feature request
TensorFlow.js version
2.0.0 Python
Describe the problem or feature request
When converting a .h5 model with custom layers to json, it's common to have the error
...
File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/converter.py", line 133, in dispatch_keras_h5_to_tfjs_graph_model_conversion
model = tf.keras.models.load_model(h5_path, compile=False)
...
ValueError: Unknown layer: LayerName
(using LayerName as a general name for the custom layer), which can be fixed by changing in converter.py the line 133 frommodel = tf.keras.models.load_model(h5_path, compile=False)
tocustom_objects_dict = {'customLayer': library.customLayer}
model = tf.keras.models.load_model(h5_path, compile=False, custom_objects=custom_objects_dict)
I understand that not all Custom Layers can be converted, but this could either be done automatically for the one which can, and only rise an error if it isn't supported; or it could be added an optional argument for passing custom layers .Code to reproduce the bug / link to feature request
!tensorflowjs_converter --input_format=keras --output_format=tfjs_graph_model --weight_shard_size_bytes=4194304 /content/model.h5 /content/model/