Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resize op convert to FP16 fail #272

Open
nistarlwc opened this issue Feb 19, 2024 · 4 comments
Open

resize op convert to FP16 fail #272

nistarlwc opened this issue Feb 19, 2024 · 4 comments
Assignees

Comments

@nistarlwc
Copy link

nistarlwc commented Feb 19, 2024

There is a model from tensorflow2onnx, the FP32 model can run successfully.

Then use float16_converter.convert_float_to_float16(onnx_model, keep_io_types=True) convert to FP16 model.
But the FP16 model can't create session, error:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from model_fp16.onnx failed:Node (Resize__846) Op (Resize) [ShapeInferenceError] Either sizes or scales must be provided, but not both of them

The problem is similar with #266.
How to solve it ?

@nistarlwc
Copy link
Author

@xiaowuhu @xadupre @skottmckay
Thanks a lot 🙏

@xadupre
Copy link
Member

xadupre commented Feb 22, 2024

The model you shared cannot be accessed. Can you try something like:

import onnx
m1 = onnx.load("<first model>")
print([n for n in m1.graph.node if n.op_type == "Resize"])
m2 = onnx.load("<second model>")
print([n for n in m1.graph.node if n.op_type == "Resize"])

My guess is the operartor Resize changed in opset 13 but the tool was not tested for the new version.

@nistarlwc
Copy link
Author

The model you shared cannot be accessed. Can you try something like:

import onnx
m1 = onnx.load("<first model>")
print([n for n in m1.graph.node if n.op_type == "Resize"])
m2 = onnx.load("<second model>")
print([n for n in m1.graph.node if n.op_type == "Resize"])

My guess is the operartor Resize changed in opset 13 but the tool was not tested for the new version.

无法访问您共享的模型。你可以尝试这样的东西:

导入onnx
m1=onnx负载(“第一模型“)
print([n] forninm1. graph. nodeifn. op_type==调整大小”])
m2=onnx负载(“第二模型“)
print([n] forninm1. graph. nodeifn. op_type==调整大小”])

我的猜测是operartor Resize在opset 13中发生了变化,但该工具没有在新版本中进行测试。

first model:

[input: "BiseNetV2/aggregation_branch/guided_aggregation_block/semantic_branch/3x3_conv_block/bn/FusedBatchNormV3:0"
input: "roi__879"
input: "roi__879"
input: "Concat__796:0"
output: "Resize__797:0"
name: "Resize__797"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
, input: "BiseNetV2/aggregation_branch/guided_aggregation_block/aggregation_features/guided_semantic_features:0"
input: "roi__879"
input: "roi__879"
input: "Concat__845:0"
output: "Resize__846:0"
name: "Resize__846"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
, input: "BiseNetV2/logits/1x1_conv_block/Conv2D:0"
input: "roi__879"
input: "roi__879"
input: "Concat__887:0"
output: "Resize__888:0"
name: "Resize__888"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
]
[input: "Resize__797_input_cast_0"
input: "Resize__797_input_cast_1"
input: "Resize__797_input_cast_2"
input: "Concat__796:0"
output: "Resize__797_output_cast_0"
name: "Resize__797"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
, input: "Resize__846_input_cast_0"
input: "Resize__846_input_cast_1"
input: "Resize__846_input_cast_2"
input: "Concat__845:0"
output: "Resize__846_output_cast_0"
name: "Resize__846"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
, input: "Resize__888_input_cast_0"
input: "Resize__888_input_cast_1"
input: "Resize__888_input_cast_2"
input: "Concat__887:0"
output: "Resize__888_output_cast_0"
name: "Resize__888"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "exclude_outside"
  i: 0
  type: INT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}
domain: ""
]

The 2 models are converted from tensorflow-onn with opset 15.

Try to use opset 12, the fp16 model can create session, but don't have result when predict.

All model in GoogleDrive
Thanks a lot

@nistarlwc
Copy link
Author

@xadupre
I try to train a pytorch model of Bisenet-V2, that can run fp16 model.
I compared the two onnx models of pytorch and tensorflow and found that tensorflow's RESIZE OP has two more parameters, scales and roi.
github

So I try to delete the parameters, use

        nodes = onnx_model.graph.node
        node_delete_list = []
        for i, node in enumerate(nodes[:]):
            node_op_type = node.op_type
            if node.op_type == "Resize":
                attrs = node.input
                for j, attr in enumerate(attrs[:]):
                    if 'const_empty_' in attr:
                        node_delete_list.append(attr)
                        nodes[i].input[j] = ''

The RESIZE OP are changed like:
github2

The fp16 model can create session, but don't have result.
I have no idea how to solve this problem.

@xiaowuhu xiaowuhu self-assigned this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants