我正在使用tensorflow js在This Guideline之后从keras加载模型 但是在这行代码
const model = await tf.loadModel('https://foo.bar/tfjs_artifacts/model.json');
我遇到错误
Error: Sequential.fromConfig called without an array of configs
at new t (app.js:26972)
at t.fromConfig (app.js:26972)
at deserializeKerasObject (app.js:26972)
at deserialize (app.js:26972)
at app.js:26972
at app.js:26972
at Object.next (app.js:26972)
at o (app.js:26972)
该如何解决?此错误的可能原因是什么? 谢谢您的帮助 。
注意:我已经在服务器中启用了cors,所以我认为这与以下问题无关 我的服务器。我正在使用本地主机(不是指南中提到的主机) 另外,正如我在文档中提到的
tfjs.keras.converters.save_keras_model()
答案 0 :(得分:0)
我会仔细检查您的model.json
。当我将Keras模型权重转换为Tensorflow.js json格式(而不是整个模型)时,我得到了完全相同的错误。也就是说,我使用model.save_weights(filepath)
而不是model.save()
保存了Keras模型。
您的问题可能与我的问题不同,但这可能与您的实际模型有关,而不是与所述模型的加载有关。
答案 1 :(得分:0)
根据https://github.com/tensorflow/tfjs/issues/744中的评论,更新您的tfjs版本:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.5"></script>
这对我有用。