Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unknown layer: Rescaling. #3728

Closed
co2nut opened this issue Aug 4, 2020 · 9 comments
Closed

Error: Unknown layer: Rescaling. #3728

co2nut opened this issue Aug 4, 2020 · 9 comments
Labels
comp:core type:feature New feature or request

Comments

@co2nut
Copy link

co2nut commented Aug 4, 2020

Getting the error when trying to load custom converted model :
Error: Unknown layer: Rescaling. 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().
@rthadur rthadur added comp:core type:feature New feature or request labels Aug 4, 2020
@rthadur
Copy link
Contributor

rthadur commented Aug 4, 2020

@co2nut this is a feature request , would you be willing to contribute ?

@roca77
Copy link

roca77 commented Sep 15, 2020

Have you guys found a solution to this? I am getting the same error...

@chihuahua
Copy link
Member

Same, I am seeing this when loading a Keras model, ie

  tf.loadLayersModel('./model_export/model.json').then(
      (m: tf.GraphModel) => {
        this.model = m;
        console.log(m);
      });

@chihuahua
Copy link
Member

My guess is that you all are using the tf.keras.layers.experimental.preprocessing.Rescaling layer, which has not yet been ported to TensorFlow JS.

@roca77
Copy link

roca77 commented Sep 28, 2020

My guess is that you all are using the tf.keras.layers.experimental.preprocessing.Rescaling layer, which has not yet been ported to TensorFlow JS.

Yes, Rescaling is causing the issue; I removed it and now it's working

@rthadur
Copy link
Contributor

rthadur commented Sep 29, 2020

Thank you , closing this issue for now

@rthadur rthadur closed this as completed Sep 29, 2020
@nwatab
Copy link

nwatab commented Nov 19, 2020

I know this issue is closed, but for visitors who uses tf.keras.applications.EfficientNetB?, it cannot be converted to tfjs because it uses Rescaling in it.
https://github.com/tensorflow/tensorflow/blob/v2.3.1/tensorflow/python/keras/applications/efficientnet.py#L316

@cardstdani
Copy link

I fixed it by adding this parameter at the conversion command: --output_format=tfjs_graph_model

After that, I loaded the model as Graph in the JavaScript code of the website. I hope it's useful

@narendraadloid
Copy link

My guess is that you all are using the tf.keras.layers.experimental.preprocessing.Rescaling layer, which has not yet been ported to TensorFlow JS.

Yes, Rescaling is causing the issue; I removed it and now it's working

I removed the scaling from the model but still it's not working
the model is defined below:

input_shape = (config.HEIGHT, config.WIDTH, 3)
base_model = keras.applications.MobileNetV3Large(weights='imagenet', input_shape=input_shape, include_top=False)
base_model.trainable = True
inputs = keras.Input(shape=input_shape)
x = base_model(inputs, training=True)
x = keras.layers.GlobalAveragePooling2D()(x)
x = keras.layers.Dropout(0.5)(x)
x = keras.layers.Dense(1024)(x)
x = keras.layers.Dense(256)(x)
x = keras.layers.Dense(64)(x)
x = keras.layers.Dense(8)(x)

outputs = keras.layers.Dense(2)(x)
model = keras.Model(inputs, outputs)
model.summary()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core type:feature New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants