【发布时间】:2019-06-16 13:59:56
【问题描述】:
我正在开发一个 chrome 扩展,我使用我训练有素的 keras 模型,通过库 tensorflow.js 下载它。
正如我从 DevTools 中看到的,模型加载正常,但我不能使用它(不能使用函数predict())。
background.js
const start = async function() {
const model = await tf.loadLayersModel('https://raw.githubusercontent.com/myAcc/myRep/master/model.json');
return model;
}
const model = start();
chrome.extension.onRequest.addListener(function predict(data){
console.log(data);
console.log(model.predict(data));
var prediction = model.predict(data);
if (prediction[0] == 1){
alert("Yes");
}
else {
alert("No");
}
}
);
manifest.json
{
"manifest_version": 2,
"name": "my_project",
"version": "0.1",
"background": {
"scripts": ["tf.min.js", "background.js"]
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery-3.1.1.min.js","content.js"]
}
],
"permissions": ["https://*/"]
}
background.js 出现错误
事件处理程序中的错误:TypeError:model.predict 不是函数
我该如何解决?
【问题讨论】:
标签: javascript json tensorflow google-chrome-extension tensorflow.js