首页 > 解决方案 > 无法使用由 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 模型是如何生成的:(

标签: tensorflow.jstensorflowjs-converter

解决方案


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


推荐阅读