【问题标题】:Unable to use models created by the tensorflowjs converter无法使用由 tensorflowjs 转换器创建的模型
【发布时间】:2020-01-15 03:37:53
【问题描述】:

我正在尝试重用由 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 demo 中使用这个新的转换模型:

// 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 模型是如何生成的 :(

【问题讨论】:

  • 没有fromTFhub属性

标签: tensorflow.js tensorflowjs-converter


【解决方案1】:
from keras.applications import MobileNetV2
model = MobileNetV2(weights='imagenet', include_top=False)

save_model(
    model,
    "mobilenet2.h5",
    overwrite=True,
)

将mobilenet特征提取器转换为js

tensorflowjs_converter --input_format keras \
                       path/to/mobilenet2.h5 \
                       path/to/tfjs_target_dir

【讨论】:

    【解决方案2】:

    relu6 的运算符刚刚添加 1 周前。它应该在下一个 TensorFlow.js 版本中可用。

    一旦发布,请尝试使用最新版本。

    见:https://github.com/tensorflow/tfjs/pull/2016

    【讨论】:

      【解决方案3】:

      此问题与新版本无关。我有同样的问题,转了一圈。如果您在 GPU 运行时(我使用 Colab GPU 运行时)中工作,则会发生此问题。您只需在 CPU 模式下 fit/fit_generate 模型,您的模型就会在快乐状态下准备就绪。

      【讨论】:

        猜你喜欢
        • 2018-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-13
        • 2020-11-09
        • 2019-12-23
        • 2020-04-13
        • 2020-01-15
        相关资源
        最近更新 更多