【问题标题】:Unhandled Rejection (Error): The shape of dict['image_tensor'] provided in model.execute(dict) must be [X,X,X,X], but was X,X,X]未处理的拒绝(错误):model.execute(dict)中提供的dict['image_tensor']的形状必须是[X,X,X,X],但是是X,X,X]
【发布时间】:2020-06-01 09:20:55
【问题描述】:

TensorFlow.js 版本 v1.5.2

浏览器版本 铬 79.0.3945.130

描述问题或功能要求 我使用 tensorflow 1.15.0 和 faster_rcnn_inception_v2_coco_2018_01_28 训练了我自己的对象。之后保存的模型使用 tensorflow 转换器转换 web 模型。 tensorflowjs 版本为 1.5.2。

This created model using web app error The shape of dict['image_tensor'] provided in model.execute(dict) must be [X,X,X,X], but was [X,X,X]

p>

创建保存的模型

python export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training/model.ckpt-XXXX --output_directory inference_graph

转换保存的模型

tensorflowjs_converter
--input_format=tf_saved_model
--output_node_names='MobilenetV1/Predictions/Reshape_1'
--saved_model_tags=serve
/mobilenet/saved_model
/mobilenet/web_model

tensorflowjs 网络应用

const img = document.getElementById('img');
const model = await tf.loadGraphModel('model.json')
model.predict(tf.browser.fromPixels(img)) // or model.predict(img)

这个过程有什么问题?

【问题讨论】:

    标签: tensorflow tensorflow.js tensorflowjs-converter


    【解决方案1】:

    这是形状不匹配错误。

    似乎模型需要 4d 张量,而您提供的是 3d 张量。 expandDimsreshape 可用于向用作参数的 3d 张量添加新维度

    【讨论】:

      【解决方案2】:

      这个错误可能是因为模型需要一批图像而不是一个图像。要修复它,可以使用 expandDims 插入额外的维度。

      const output = model.predict(tf.fromPixels(image).expandDims(0));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-19
        • 1970-01-01
        • 2019-10-04
        • 1970-01-01
        • 1970-01-01
        • 2018-01-17
        • 1970-01-01
        相关资源
        最近更新 更多