私は、Keras.jsライブラリを使ってPythonで生成された基本的なKerasモデルをウェブサイトに実装しようとしています。今、モデルを訓練し、model.json
、model_weights.buf
、およびmodel_metadata.json
ファイルにエクスポートしました。さて、私は基本的にgithubページのテストコードをコピーして貼り付けて、モデルがブラウザに読み込まれるかどうかを確認しましたが、残念ながらエラーが発生しています。ここにテストコードがあります。 (編集:私は多少の誤差が、残りについては下記を参照の固定)Keras.jsでウェブサイトにKerasモデルを実装する
var model = new KerasJS.Model({
filepaths: {
model: 'dist/model.json',
weights: 'dist/model_weights.buf',
metadata: 'dist/model_metadata.json'
},
gpu: true
});
model.ready()
.then(function() {
console.log("1");
// input data object keyed by names of the input layers
// or `input` for Sequential models
// values are the flattened Float32Array data
// (input tensor shapes are specified in the model config)
var inputData = {
'input_1': new Float32Array(data)
};
console.log("2 " + inputData);
// make predictions
return model.predict(inputData);
})
.then(function(outputData) {
// outputData is an object keyed by names of the output layers
// or `output` for Sequential models
// e.g.,
// outputData['fc1000']
console.log("3 " + outputData);
})
.catch(function(err) {
console.log(err);
// handle error
});
編集:だから私はJS 5と互換性があるように少しの周りに私のプログラムを変更し(それは私の一部の愚かな間違いだった)、および今私は別のエラーが発生しました。このエラーは検出され、ログに記録されます。私が得るエラーは:Error: predict() must take an object where the keys are the named inputs of the model: input.
私のdata
変数が正しい形式でないため、この問題が発生すると思います。モデルで28x28の配列を取った場合、正しい出力を正しく予測できるように、data
も28x28の配列にする必要があると私は考えました。しかし、私は何かが欠けていると信じているので、エラーがスローされている理由です。 This質問は私のものと非常に似ていますが、PythonではJSではありません。ここでもまた、どんな助けもありがたいです。