仅显示图像的AutoMl边缘模型

2024-04-29 11:04:45 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我是ml新手,在automl上工作,它在线显示预测效果要好得多,但问题是我需要一个离线解决方案,所以我在边缘Tensorflow上部署模型,一旦我训练了模型并将其离线下载。我得到了一个标签txt文件,3个bin文件和1个JSON文件格式的模型文件

我确实读过这篇Google Edge Vision但是我仍然无法让我的模型工作,因为这个链接显示我们必须制作一个index.html文件我确实复制粘贴了相同的代码并制作了一个html文件,但我不想从google存储加载图像,所以我给出了与index.html文件在同一文件夹中的图像路径,并删除了交叉源,但仍然,它只是显示图像,而不是检测图像的概率或诸如此类的东西,是的,我用python打开了Http.server8080,所以没有问题

<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>
<img id="detect" src="1.png">

<script>

async function run() {
const model = await tf.automl.loadImageClassification('model.json');
  const image = document.getElementById('detect');
  const predictions = await model.classify(image);
  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>

有人能帮我吗?我该怎么办?我已经搜索了很多网络论坛,但都找不到答案


Tags: 文件模型图像srcjsonindexmodelhtml
1条回答
网友
1楼 · 发布于 2024-04-29 11:04:45

我可以根据官方文件在当地核实预测。 JS代码或文件上的配置可能会丢失。 我想我修改了一些文件,但我不记得是哪一个,所以我会在我的工作版本中列出所有相关的代码,这样你就可以比较了。 浏览器和Javascript控制台也值得检查(在Chrome中查看>;开发者>;Javascript控制台)。我的quickstart Tensorflow.js工作预测正在Chrome上运行

dict.txt

sunflowers
tulips
dandelion
roses
daisy

image.jpeg
binaryfile.bin
index.html

<head>
</head>
<body>
    <script src="https://unpkg.com/@tensorflow/tfjs"></script>
    <script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>
    <img id="daisy" crossorigin="anonymous" src="./download.jpeg">
    <script>
    async function run() {
        const model = await tf.automl.loadImageClassification('model.json');
        const image = document.getElementById('daisy');
        const predictions = await model.classify(image);
        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>
<body>

请注意,我将脚本标记放在正文中,因为您希望预测显示在页面内容中,就像在教程中一样

model.json

working auto ML edge export tf.js

相关问题 更多 >