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

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

Open
marigoold opened this issue Jul 29, 2022 · 1 comment

Comments

@marigoold
Copy link
Contributor

复现代码

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) 这一行注释掉就可以成功转换。

@marigoold
Copy link
Contributor Author

随机初始化的模型,设置成eval时候,bn的running stat可能不稳定导致参数爆炸,可以用预训练的模型权重倒入再测试

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

1 participant