Search code examples
tensorflowtensorflow.js

Failure to load model in tensorflow.js


I have converted different transfer trained models (VGG16, InceptionV3, EfficientNetB0) from tensorflow in python to tensorflowjs. And after implementing into tensorflowjs, it fails to load the model.

One of the error is:

Uncaught Error: Unknown layer: Functional. 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 models.js:295
    at u (runtime.js:45)
    at Generator._invoke (runtime.js:274)
    at Generator.forEach.t.<computed> [as next] (runtime.js:97)
    at Wm (runtime.js:728)

Also, there is

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)

Also,

Failed to load resource: the server responded with a status of 404 ()

What is the problem? If I use the .json file generated from teachable machine, the model can be loaded. (However, the predictions become completely wrong for unknown reasons, and the problems seems to be more than just labelling issue.) But if I use model.json file generated from .h5 or SavedModel via tensorflow converter, no matter which pretrained models I use, or the file formats (.h5 or SavedModel) to generate, the model cannot be loaded into the javascript.

Please help!!


Solution

  • Go to the model.json file and search for the keyword Functional(you could use ctrl+f Functional) and replace the word with Model.