我想加载keras
已转换为tensorflow.js
兼容格式的模型来执行推理。我的代码看起来像这样
import * as tf from '@tensorflow/tfjs';
import "regenerator-runtime/runtime.js";
import 'bootstrap/dist/css/bootstrap.css';
const model_path = '/home/user/Desktop/Github/tfjs_model/tfjs/tfjs_model/model.json';
async function loadModel(path){
console.log("Model loading in progress from ".concat(path));
const model = await tf.loadLayersModel(path);
console.log("Model Loaded Successfully");
return model;
};
const model = loadModel(model_path);
const input = tf.tensor1d([1], [13]);
console.log(model.predict(input));
我收到了这个错误
Error: Failed to parse model JSON of response from /home/user/Desktop/Github/tfjs_model/tfjs/tfjs_model/model.json'. Please make sure the server is serving valid JSON for this request.
,我查看了很多地方(Github 问题,堆栈溢出),但似乎找不到修复方法。如何解决?`