尝试运行 https://glitch.com/~tar-understood-exoplanet 时,模型无法加载,并且我无法启用网络摄像头。
有人遇到过同样的问题吗?
程序运行时,控制台中显示以下信息:
tfjs:2 Uncaught (in promise) Error: The dtype of dict['image_tensor'] provided in model.execute(dict) must be int32, but was float32 at Object.b [as assert] (tfjs:2) at tfjs:2 at Array.forEach (<anonymous>) at t.checkInputShapeAndType (tfjs:2) at t.<anonymous> (tfjs:2) at tfjs:2 at Object.next (tfjs:2) at tfjs:2 at new Promise (<anonymous>) at Zv (tfjs:2)
我使用的是 Macbook Pro,其他一些使用 Windows 系统的朋友在运行模型时也遇到了问题。我们还尝试了不同的浏览器,包括 Safari 和 Chrome。
成功!切换到 coco-ssd 2.0.2 后:
我在第 62 行添加了版本 2.0.2,如下所示:
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/[email protected]"></script>
回答:
这是由 coco-ssd 的预热运行引起的,该运行使用了 tf.zeros 张量。在 TFJS 的最新版本中,tf.zeros 的默认 dtype 是 ‘float’。我已经发布了一个包含修复的新版本。如果您在 glitch 示例(index.html)中使用 coco-ssd 的最新版本(2.0.2),应该可以正常工作,如下所示。
<!-- Load the coco-ssd model to use to recognize things in images --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/[email protected]"></script>