问题描述
准确地使用https://cloud.google.com/vision/automl/object-detection/docs/edge-quickstart将automl创建的最新模型用于tensorflowjs进行边缘处理时。
看到这个问题,从用于tensorflowjs的automl导出模型并在浏览器中使用。
跑步时
const predictions = await model.detect(img,options);
出现以下错误:
util.js:109 Uncaught (in promise) Error: The shape of dict['ToFloat'] provided in model.execute(dict) must be [],but was [1,1280,1920,3]
at Ev (util.js:109)
at graph_executor.js:543
at Array.forEach (<anonymous>)
at e.t.checkInputShapeAndType (graph_executor.js:534)
at e.<anonymous> (graph_executor.js:332)
at u (runtime.js:45)
at Generator._invoke (runtime.js:274)
at Generator.forEach.e.<computed> [as next] (runtime.js:97)
at Um (runtime.js:728)
at o (runtime.js:728)
使用
"@tensorflow/tfjs": "^2.6.0","@tensorflow/tfjs-automl": "^1.0.0"
完整代码
<script src="/node_modules/@tensorflow/tfjs/dist/tf.min.js"></script>
<script src="/node_modules/@tensorflow/tfjs-automl/dist/tf-automl.min.js"></script>
<img id="img" src="salad.jpg">
<script>
async function run() {
const model = await tf.automl.loadobjectDetection('/model/model.json');
const img = document.getElementById('img');
const options = { score: 0.5,IoU: 0.5,topk: 20 };
console.log(model.dictionary);
const predictions = await model.detect(img,options);
console.log(predictions);
// Show the resulting object on the page.
const pre = document.createElement('pre');
pre.textContent = JSON.stringify(predictions,null,2);
document.body.append(pre);
}
run();
</script>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)