1
votes

I have trained a model via tensorflow in python, using image augmentation incorporated into the model layers. However, when I converted to trained model to tensorflow.js (model.json) and run it, there is an error:

jquery-3.3.1.slim.min.js:2 Uncaught Error: Unknown layer: RandomFlip. This may be due to one of the following reasons:
1. The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at jN (generic_utils.js:242)
    at GI (serialization.js:31)
    at e.fromConfig (models.js:1026)
    at jN (generic_utils.js:277)
    at GI (serialization.js:31)
    at e.fromConfig (models.js:1026)
    at jN (generic_utils.js:277)
    at GI (serialization.js:31)
    at models.js:295
    at u (runtime.js:45)

Here is the content of the model.json file: https://github.com/maximus3219/maximus3219.github.io/blob/main/Flower_model_EN0/model.json

This is probably due to augmentation operations. How should I deal with the problems? Thanks!

1
How did you convert the model in TFJS converter? - yudhiesh
import tensorflowjs as tfjs import tensorflow as tf src_path = 'G:/Deep learning/test.h5' target_path = 'G:/Deep learning/Test/' model = tf.keras.models.load_model(src_path) tfjs.converters.save_keras_model(model,target_path) - Maximus
Could you try converting it like this in the notebook !tensorflowjs_converter --input_format keras --output_format=tfjs_graph_model G:/Deep learning/test.h5 G:/Deep learning/Test/? Or from the command line by just removing the !. - yudhiesh
I'm sorry, can you tell me where I can use the 'notebook'? - Maximus
I meant if it is a Jupyter notebook - yudhiesh

1 Answers

2
votes

There must be some sort of issue when converting the keras model to tensorflow.js format so converting it like this will work

tensorflowjs_converter --input_format keras --output_format=tfjs_graph_model G:/Deep learning/test.h5 G:/Deep learning/Test/