tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.42k stars 1.92k forks source link

tfjs classification model in react native app - Error: Unknown layer: Normalization #7639

Open brianspiesman opened 1 year ago

brianspiesman commented 1 year ago

I trained a custom EfficientNetB2 classification model with Tensorflow 2.9.0:

base_model = EfficientNetB2(include_top=False, pooling ='avg', weights='imagenet', input_shape=(IMG_SIZE, IMG_SIZE, 3))
x = base_model.output
x = Dense(1024, activation='relu')(x)
x = Dropout(0.01)(x)
predictions = Dense(num_classes, activation='softmax')(x)
model = Model(inputs = base_model.input, outputs = predictions)

I then converted the resulting .h5 saved model to tfjs (using tensorflowjs 3.19.0): tfjs.converters.save_keras_model(saved_model, 'tfjs_model')

After the conversion completes I get this message: weight normalization_3/count with shape () and dtype int64 was auto converted to the type int32

Then, when I use the tfjs model in a react native app, I get this error message:

Possible Unhandled Promise Rejection (id: 2):
Error: Unknown layer: Normalization. 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().

I am using @tensorflow/tfjs 4.4.0

This seems to be an error related to normalization but I am not sure how to address it.

Any help would be appreciated!

brianspiesman commented 1 year ago

Is this an appropriate place to ask this question or is another forum more appropriate?

brianspiesman commented 1 year ago

@Linchenn any ideas here?

geminigeek commented 1 year ago

having same issue !! i trained a model in EfficientNetB0 , same error is showing , did you find any solution ?

brianspiesman commented 1 year ago

Nope. No response. I've moved on to a different approach.

fernandozet commented 1 year ago

I used tensorflow.keras.layers.Normalization() in my model and I am getting the same error. Did you guys find a workaround for this issue?

alena424 commented 9 months ago

same issue

jatinvinkumar commented 9 months ago

I have the same issue. Has anyone found a workaround?