0
votes

I have a GRU based model . I have converted it for tensorflow js . While loading it iin tfjs getting an error

Unhandled Rejection (Error): GRUCell does not support reset_after parameter set to true.

I have attached corresponding json . Please advice

{"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v2.7.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 48, 64], "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}}, {"class_name": "LayerNormalization", "config": {"name": "layer_normalization", "trainable": true, "dtype": "float32", "axis": [2], "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"class_name": "Zeros", "config": {}}, "gamma_initializer": {"class_name": "Ones", "config": {}}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null}}, {"class_name": "Conv1D", "config": {"name": "conv1d", "trainable": true, "dtype": "float32", "filters": 32, "kernel_size": [3], "strides": [1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "BatchNormalization", "config": {"name": "batch_normalization", "trainable": true, "dtype": "float32", "axis": [2], "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"class_name": "Zeros", "config": {}}, "gamma_initializer": {"class_name": "Ones", "config": {}}, "moving_mean_initializer": {"class_name": "Zeros", "config": {}}, "moving_variance_initializer": {"class_name": "Ones", "config": {}}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null}}, {"class_name": "MaxPooling1D", "config": {"name": "max_pooling1d", "trainable": true, "dtype": "float32", "strides": [3], "pool_size": [3], "padding": "valid", "data_format": "channels_last"}}, {"class_name": "Conv1D", "config": {"name": "conv1d_1", "trainable": true, "dtype": "float32", "filters": 32, "kernel_size": [3], "strides": [1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1], "groups": 1, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dropout", "config": {"name": "dropout", "trainable": true, "dtype": "float32", "rate": 0.25, "noise_shape": null, "seed": null}}, {"class_name": "GRU", "config": {"name": "gru", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 40, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2, "reset_after": true}}, {"class_name": "GRU", "config": {"name": "gru_1", "trainable": true, "dtype": "float32", "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 40, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2, "reset_after": true}}, {"class_name": "Flatten", "config": {"name": "flatten", "trainable": true, "dtype": "float32", "data_format": "channels_last"}}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 100, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dropout", "config": {"name": "dropout_1", "trainable": true, "dtype": "float32", "rate": 0.25, "noise_shape": null, "seed": null}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 2, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}}, "training_config": {"loss": {"class_name": "SparseCategoricalCrossentropy", "config": {"reduction": "auto", "name": "sparse_categorical_crossentropy", "from_logits": true}}, "metrics": ["accuracy"], "weighted_metrics": null, "loss_weights": null, "optimizer_config": {"class_name": "Adam", "config": {"name": "Adam", "learning_rate": 0.0010000000474974513, "decay": 0.0, "beta_1": 0.8999999761581421, "beta_2": 0.9990000128746033, "epsilon": 1e-07, "amsgrad": false}}}}, "weightsManifest": [{"paths": ["group1-shard1of1.bin"], "weights": [{"name": "batch_normalization/gamma", "shape": [32], "dtype": "float32"}, {"name": "batch_normalization/beta", "shape": [32], "dtype": "float32"}, {"name": "batch_normalization/moving_mean", "shape": [32], "dtype": "float32"}, {"name": "batch_normalization/moving_variance", "shape": [32], "dtype": "float32"}, {"name": "conv1d/kernel", "shape": [3, 64, 32], "dtype": "float32"}, {"name": "conv1d/bias", "shape": [32], "dtype": "float32"}, {"name": "conv1d_1/kernel", "shape": [3, 32, 32], "dtype": "float32"}, {"name": "conv1d_1/bias", "shape": [32], "dtype": "float32"}, {"name": "dense/kernel", "shape": [40, 100], "dtype": "float32"}, {"name": "dense/bias", "shape": [100], "dtype": "float32"}, {"name": "dense_1/kernel", "shape": [100, 2], "dtype": "float32"}, {"name": "dense_1/bias", "shape": [2], "dtype": "float32"}, {"name": "gru/gru_cell/kernel", "shape": [32, 120], "dtype": "float32"}, {"name": "gru/gru_cell/recurrent_kernel", "shape": [40, 120], "dtype": "float32"}, {"name": "gru/gru_cell/bias", "shape": [2, 120], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/kernel", "shape": [40, 120], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/recurrent_kernel", "shape": [40, 120], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/bias", "shape": [2, 120], "dtype": "float32"}, {"name": "layer_normalization/gamma", "shape": [64], "dtype": "float32"}, {"name": "layer_normalization/beta", "shape": [64], "dtype": "float32"}]}]}

1
Maybe you can open an issue on githubedkeveked
Did you find any solution to this problem? I currently have this problem and can’t find anythingMarco Ripamonti
@Macro , No, I did not get solution. But some where I found that python based new gru cell is different from js based one. Latest changes are not yet available in tfjsMasthan

1 Answers

0
votes

I had the same issue. I tried doing exactly what the exception suggest when training the model on python. Modified the cell initialization from:

memory_layer = tf.keras.layers.GRUCell(units=memory_size, name='memory')

to

memory_layer = tf.keras.layers.GRUCell(units=memory_size, reset_after=False, name='memory')

After re training the model with the change and exporting to tfjs, I was able to load it. This flag changes the cell internal architecture, but in my case it didn't have a performance impact in the model.