Json TensorflowJS无法加载模型

Json TensorflowJS无法加载模型,json,tensorflow.js,tensorflowjs-converter,Json,Tensorflow.js,Tensorflowjs Converter,我用Keras构建和训练了一个模型,并用tensorflowjs转换器(tfjs.converts.save_Keras_model()函数)保存了它 稍后,在尝试将其加载到tensorflowjs中时,出现以下错误: 错误:顺序模型中的第一层必须获得“inputShape”或“batchInputShape”参数。 但是在检入包含模型结构的JSON文件后,指定了一个输入形状。 知道tfjs为什么不能加载它吗? 这可能是由不同的变量名引起的(在我的JSON文件中是batch\u input\u

我用Keras构建和训练了一个模型,并用tensorflowjs转换器(tfjs.converts.save_Keras_model()函数)保存了它

稍后,在尝试将其加载到tensorflowjs中时,出现以下错误:
错误:顺序模型中的第一层必须获得“inputShape”或“batchInputShape”参数。

但是在检入包含模型结构的JSON文件后,指定了一个输入形状。 知道tfjs为什么不能加载它吗? 这可能是由不同的变量名引起的(在我的JSON文件中是
batch\u input\u shape
,在错误消息中是
batchInputShape

以下是我如何构建和培训模型:

    model.add(LSTM(128, dropout=0.2, input_shape=(time_steps, input_dim) ))
    model.add(Dense(output_dim, activation='sigmoid'))

    model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
    model.fit_generator(generator=train_generator,
                          steps_per_epoch=steps_per_epoch,
                          epochs=epochs,
                          validation_data=valid_generator,
                          validation_steps=valid_steps
                        )
这是JSON文件。我不知道第三个
null
变量来自哪里,但是如果我更改它,我会得到一个错误,说明维度的数量是错误的

    "format": "layers-model", 
    "generatedBy": "keras v2.3.1", 
    "convertedBy": "TensorFlow.js Converter v1.4.0", 
    "modelTopology": {
        "keras_version": "2.3.1", 
        "backend": "tensorflow", 
        "model_config": {
            "class_name": "Sequential", 
            "config": {
                "name": "sequential_1", 
                "layers": [
                    {
                        "class_name": "LSTM", 
                        "config": {
                            "name": "lstm_1", 
                            "trainable": true, 
                            "batch_input_shape": [null, 10, 100], 
                            "dtype": "float32", 
                            "return_sequences": false, 
                            "return_state": false, 
                            "go_backwards": false, 
                            "stateful": false, 
                            "unroll": false, 
                            "units": 128, 
                            "activation": "tanh", 
                            "recurrent_activation": "sigmoid", 
                            "use_bias": true, 
                            "kernel_initializer": {
                                "class_name": "VarianceScaling", 
                                "config": {
                                    "scale": 1.0, 
                                    "mode": "fan_avg", 
                                    "distribution": "uniform", 
                                    "seed": null
                                }
                            }, 
                            "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, 
                            "bias_initializer": {"class_name": "Zeros", "config": {}}, 
                            "unit_forget_bias": true, 
                            "kernel_regularizer": null, 
                            "recurrent_regularizer": null, 
                            "bias_regularizer": null, 
                            "activity_regularizer": null, 
                            "kernel_constraint": null, 
                            "recurrent_constraint": null, 
                            "bias_constraint": null, 
                            "dropout": 0.2, 
                            "recurrent_dropout": 0.0, 
                            "implementation": 2
                        }
                    }, 
                    {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 29, "activation": "sigmoid", "use_bias": true, "kernel_initializer": 
                    {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "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": {
            "optimizer_config": {
                "class_name": "Adam", 
                "config": {
                    "learning_rate": 0.0010000000474974513, 
                    "beta_1": 0.8999999761581421, 
                    "beta_2": 0.9990000128746033, 
                    "decay": 0.0, 
                    "epsilon": 1e-07, 
                    "amsgrad": false
                }
            }, 
            "loss": "mse", 
            "metrics": ["accuracy"], 
            "weighted_metrics": null, 
            "sample_weight_mode": null, 
            "loss_weights": null
        }
    }, 
    "weightsManifest": [{
        "paths": ["group1-shard1of1.bin"], 
        "weights": [
            {"name": "dense_1/kernel", "shape": [128, 29], "dtype": "float32"}, 
            {"name": "dense_1/bias", "shape": [29], "dtype": "float32"}, 
            {"name": "lstm_1/kernel", "shape": [100, 512], "dtype": "float32"}, 
            {"name": "lstm_1/recurrent_kernel", "shape": [128, 512], "dtype": "float32"}, 
            {"name": "lstm_1/bias", "shape": [512], "dtype": "float32"}
        ]
    }]
}

我也遇到了同样的问题,我只上传了model.json文件,而没有上传同样由tensorflowjs_转换器创建的bin文件。确保已将model.json文件和.bin文件上载到同一文件夹中。model.json文件使用.bin文件获取权重。

我也遇到了同样的问题,我只上传了model.json文件,而没有上传同样由tensorflowjs_转换器创建的bin文件。确保已将model.json文件和.bin文件上载到同一文件夹中。model.json文件使用.bin文件获取权重。

在首次加载model.json文件之前,您是否更改了该文件?由于它正在抱怨
inputShape
,您可以添加
input\u-shape:[10100]
看看您有什么错误吗?我在将input\u-shape更改为[10100]时遇到的错误是
错误:input 0与层lstm\u 2不兼容:预期的ndim=3,如果您使用
input\u-shape:[null,10100]
,您仍然有相同的问题吗?否,我得到
错误:顺序模型中的第一层必须得到“inputShape”或“batchInputShape”参数。
与前面的传输一样,回滚到
inputShape:[10,100]
我没有与第一次相同的错误消息第一次加载model.json文件之前您是否更改了该文件?因为它抱怨
inputShape
,请您添加
input\u-shape:[10100]
看看您有什么错误?将input\u-shape更改为[10100]时出现的错误是
错误:输入0与层lstm_2不兼容:预期ndim=3,如果使用
输入_形状,则发现ndim=2
:[null,10100]
,您仍然有相同的问题吗?否,我得到
错误:顺序模型中的第一层必须得到“inputShape”或“batchInputShape”参数。
与以前的传输一样,回滚到
输入形状:[10100]
我没有第一次收到的错误消息