tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

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

Open brianspiesman opened this issue 2 years ago • 9 comments

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 avatar Apr 28 '23 21:04 brianspiesman

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

brianspiesman avatar May 04 '23 19:05 brianspiesman

@Linchenn any ideas here?

brianspiesman avatar May 11 '23 17:05 brianspiesman

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

geminigeek avatar Jul 27 '23 18:07 geminigeek

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

brianspiesman avatar Jul 27 '23 18:07 brianspiesman

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?

fernandozet avatar Aug 03 '23 13:08 fernandozet

same issue

alena424 avatar Jan 05 '24 16:01 alena424

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

jatinvinkumar avatar Jan 22 '24 05:01 jatinvinkumar