Skip to content

Converting SSD MobileNet V2 tensorflow frozen graph .pb file to onnx model and quantizing it using Onnx Runtime #1805

@The-ButterflyEffect

Description

@The-ButterflyEffect

``Hi, I am trying to convert SSD Mobilenet V2 tensorflow model ( frozen graph .pb format) to onnx.
I see group attr of the first Conv op in the converted onnx model equal to 0.
This invalid "group=0" then throws error when I attempt to quantize this onnx model using onnxruntime.

onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running Conv node. Name:'Conv__8004' Status Message: Input channels C is not equal to kernel channels * group. C: 3 kernel channels: 3 group: 0

Used the following python script for conversion:

import onnx
import tf2onnx
import tensorflow as tf

shape_dict = {"image_tensor:0": (3,300,300,3)}
tf_compat_v1 = tf.compat.v1
with tf_compat_v1.gfile.GFile("./frozen_inference_graph.pb", "rb") as f:
    graph_def = tf_compat_v1.GraphDef()
    graph_def.ParseFromString(f.read())

onnx_model, _ = tf2onnx.convert.from_graph_def(graph_def, input_names=["image_tensor:0"], output_names=["num_detections:0", "detection_boxes:0", "detection_scores:0", "detection_classes:0"], opset=11, shape_override=shape_dict)
onnx.save(onnx_model, "model.onnx")

Got the frozen ssd mobilenet v2 model from here: https://gist.github.com/qianlin404/c7991048c5f3264ce13d520ce0274493

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions