Skip to content

人脸识别的iresnet,在graph模式下开了fuse_add_to_output,无法通过数值check #69

@marigoold

Description

@marigoold

复现代码

import tempfile
import oneflow as flow
from oneflow_onnx.oneflow2onnx.util import convert_to_onnx_and_check
from flowvision.models.face_recognition import iresnet50

model = iresnet50().to("cuda")

class ModelGraph(flow.nn.Graph):
    def __init__(self, model):
        super().__init__()
        self.config.allow_fuse_add_to_output(True)
        self.backbone = model

    def build(self, x):
        x = x.to("cuda")
        out = self.backbone(x)
        return out

model.eval()
model_graph = ModelGraph(model)
model_graph._compile(flow.randn(1, 3, 112, 112))


with tempfile.TemporaryDirectory() as tmpdirname:
    flow.save(model.state_dict(), tmpdirname)
    convert_to_onnx_and_check(
        model_graph, flow_weight_dir=tmpdirname, onnx_model_path="./", print_outlier=True)

报错

File ~/miniconda/lib/python3.9/site-packages/oneflow_onnx/oneflow2onnx/util.py:102, in compare_result(a, b, rtol, atol, print_outlier)
    100         if np.abs(a[i] - b[i]) > atol + rtol * np.abs(b[i]):
    101             print("a[{}]={}, b[{}]={}".format(i, a[i], i, b[i]))
--> 102 assert np.allclose(a, b, rtol=rtol, atol=atol)

AssertionError:

但是 self.config.allow_fuse_add_to_output(True) 这一行注释掉就可以成功转换。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions