Error: Layer invocation in the presence of activity regularizer(s) is not supported yet

168 Views Asked by At

I'm using tf.loadLayersModel() to load into tf.js and get this error:

Error: Layer invocation in the presence of activity regularizer(s) is not supported yet.

I am using an L2 regularizer and to ensure it works properly I am also including this:

class L2 {

  static className = 'L2';

  constructor(config) {
     return tf.regularizers.l2(config)
  }
}
tf.serialization.registerClass(L2);

What is the issue?

NOTE: This is a Tensorflow model being moved to Tf.js, but Tf.js supports activity regularizers.

UPDATE:

Here is the source code for the unimplemented error. So is it not possible to load a Keras model with regularizers?

1

There are 1 best solutions below

0
On

Well, based on the message, and the link to the repo you provided

I looked at my python code and commented activity_regularizer parameters in tf.keras.layers.Dense() and it seems to work after generation with tensorflowjs_converter (at least javascript doesn't show errors).

 model = tf.keras.Sequential([
        # ...
        tf.keras.layers.Dense(64, activation='relu',
                              kernel_initializer=tf.keras.initializers.HeNormal(),
                              # activity_regularizer=tf.keras.regularizers.l2(1e-04) --> 
                              # ^ Comment line above because not working on tensorflow.js
        # ...
    ])