Error while importing efficientnet lite0 model

I have trained a model using tensorflow model maker

model = image_classifier.create(
    train_data, 
    train_whole_model= False,
    epoch=5
)

and exporting it:

model.export(export_dir='./tfjs-model', export_format=ExportFormat.TFJS)

then with tensorflow js I load it:

model = await tf.loadLayersModel(“./tfjs-model/model.json”);

but it throws the following error

Unknown layer: HubKerasLayerV1V2. 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 deserializeKerasObject (generic_utils.js:227)
    at deserialize (serialization.js:25)
    at fromConfig (models.js:861)
    at deserializeKerasObject (generic_utils.js:258)
    at deserialize (serialization.js:25)
    at loadLayersModelFromIOHandler (models.js:222)

I have also tried to export the model with tensorflow js, but I get the same error

`tensorflowjs_converter --input_format=tf_saved_model --output_node_names=‘efficientnet-b0/model/blocks_1/tpu_match_normalization’ --saved_model_tags=./model ./tfjs-model2

Hi @rolo ,

I Apologies for the late response. It’s a known issue in tfjs-converter where custom layers created by TensorFlow or Keras can’t be converted to TensorFlow.js models.

The workaround for this issue is to load your model as a Graph model instead of a Layer model .

You can convert your model to a Graph model using the following command:

tensorflowjs_converter --input_format keras --output_format=tfjs_graph_model keras-h5 model.json

Use this command to load the model:

const model = tf.loadGraphModel('/model/model.json').

Let me know, if it works for you.

Thank You!!

Hi @rolo ,

I apologize for the late response. The custom layer that you are creating needs to be registered with the serialization map of TFJS so that it can be serialized and deserialized.

This example might help you resolve your issue:

import * as tf from '@tensorflow/tfjs';
// Assuming your custom layer class is named 'MyCustomLayer'
tf.serialization.registerClass(MyCustomLayer);
const model = await tf.loadLayersModel('your_model.json');

Let me know if this helps. Thank you!