tensorflow.js - 无法使用由 tensorflowjs 转换器创建的模型
问题描述
我正在尝试重用由 tensorflow 创建的 tensorflowjs 模型。为了了解转换器的工作原理,我尝试转换 mobilenetv2 模型:
tensorflowjs_converter --input_format=tf_hub --output_format=tensorflowjs 'https://tfhub.dev/google/imagenet/mobilenet_v2_050_224/classification/2' ./web_model
这似乎行得通。然后我尝试通过更改模型的加载方式在mobilenet 演示中使用这个新的转换模型:
// const model = await mobilenet.load({version, alpha});
// replaced by
const model = await mobilenet.load({ modelUrl: './web_model/model.json', version, alpha, inputRange: [0, 1], fromTFHub: true });
// Classify the image.
const predictions = await model.classify(img);
分类调用触发错误:
Uncaught (in promise) Error: Activation relu6 has not been implemented for the WebGL backend.
我不知道官方的 tensorflowjs mobilenet 模型是如何生成的:(
解决方案
此问题与新版本无关。我有同样的问题,转了一圈。如果您在 GPU 运行时(我使用 Colab GPU 运行时)中工作,则会发生此问题。您只需在 CPU 模式下 fit/fit_generate 模型,您的模型就会在快乐状态下准备就绪。
推荐阅读
- c# - 调用 MainWindow 时出现 System.StackOverflowException
- reactjs - 道具“已禁用”的值无效
- php - 尽管被拒绝,但允许发布请求
- javascript - 过滤对象数组返回空数组
- php - 使用ajax提交文件上传时出现问题
- r - 比较 R 数据框中的列
- elasticsearch - Kibana Lens - 有没有办法只计算一个字段而不是所有记录?
- sql - 为什么 time_bucket_gapfill 在第 10 个请求时始终抛出 PSQLException?
- javascript - 获取文档属性的 Web 脚本
- wordpress - 为注册用户寻找能够上传图片的解决方案