簡體   English   中英

tensorflow js加載gru模型

[英]tensorflow js loading gru model

我有一個基於 GRU 的模型。 我已經將它轉換為 tensorflow js 。 在 tfjs 中加載時出現錯誤

未處理的拒絕(錯誤):GRUCell 不支持將 reset_after 參數設置為 true。

我附上了相應的 json 。 請指教

{"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":真,“規模”:真,“beta_initializer”:{“class_name”:“零”,“配置”:{}},“gamma_initializer”:{“class_name”:“一個”,“配置”:{}}, "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", "火車能夠”:真,“dtype”:“float32”,“步幅”:[3],“pool_size”:[3],“填充”:“有效”,“數據格式”:“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, "unr oll": 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_constr aint": 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”,“單位”:2,“激活”:“線性”,“use_bias”:真,“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,“衰減”: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", "形狀": [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"}]}]}

我遇到過同樣的問題。 在 python 上訓練模型時,我嘗試完全按照異常建議進行操作。 修改了單元格初始化:

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

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

在使用更改重新訓練模型並導出到 tfjs 后,我能夠加載它。 這個標志改變了單元的內部架構,但在我的例子中,它對模型的性能沒有影響。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM