MNN icon indicating copy to clipboard operation
MNN copied to clipboard

模型推理结果异常

Open stricklandye opened this issue 1 year ago • 10 comments

问题描述

我的模型从 tensorflow 1.x 而来,里面包含了 LSTM,转为MNN模型以后,推理结果的部分数据TF误差很大(超过了0.01),原模型使用 TF 多次推理结果是正常的。 另外一个问题是,上述模型使用MNN推理多次时结果存在跳变,并且两次推理之间结果误差也超过了(0.01)。

限于个人能力,无法排查问题到底在哪儿,希望社区能提供一些帮助。

PS: github 不允许上传超过 35mb 的文件,如果需要测试代码的话,麻烦提供一个邮箱给我。

Version

MNN: v2.8.1 Tensorflow: 1.15.1 OS: 6.5.0-15-generic #15~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 12 18:54:30 UTC 2 x86_64 GNU/Linux

编译环境

无编译错误

其他问题

该模型用repo里的testMNNFromTf.py运行会有概率出现如下的错误:

TensorArray has size zero, but element shape [?,512] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
         [[{{node lstm/TensorArrayStack/TensorArrayGatherV3}}]]

请问这是为什么? 是MNN的bug还是我的使用方式有问题?

stricklandye avatar Feb 02 '24 08:02 stricklandye

这个错误是在使用 tensorflow 推理,生成测试数据的过程出的。原因是 testMNNFromTf.py 会随机构造输入,有些输入可能是无效的。找一组运行通过的就可以了。

jxt1234 avatar Feb 05 '24 02:02 jxt1234

发下你的使用代码,另外可以用 ./SequenceModuleTest.out 去测试多次输入的情况。现在无法判断是否是你使用代码的问题。

jxt1234 avatar Feb 05 '24 02:02 jxt1234

发送到我邮箱即可,[email protected]

jxt1234 avatar Feb 05 '24 02:02 jxt1234

感谢大佬帮助,我稍后整理一下发到邮箱里。

stricklandye avatar Feb 05 '24 03:02 stricklandye

@jxt1234 大佬,名为 《MNN推理结果异常反馈》的邮件已经发送了,再次感谢热心帮助。

stricklandye avatar Feb 05 '24 06:02 stricklandye

@stricklandye 请教个不相关问题哈:你是直接tf转mnn格式吗?没有经过通用onnx格式吗?谢谢

thelou1s avatar Feb 06 '24 07:02 thelou1s

看了下推理的代码没有考虑 输入的 NC4HW4 布局,转 mnn 模型时加上 --keepInputFormat 吧,测试了下加上这个选项后用原来代码推理结果就正常了。

jxt1234 avatar Feb 06 '24 11:02 jxt1234

与 tf 的对比方面,基于 testMNNFromTf.py ,修改下代码里面 tf 输入的部分,构造测试用例对比吧。

jxt1234 avatar Feb 06 '24 11:02 jxt1234

@stricklandye 请教个不相关问题哈:你是直接tf转mnn格式吗?没有经过通用onnx格式吗?谢谢

是的,我直接将tf转为forzen model,然后转MNN。如果你有tf->onxx->mnn的需求,可以参考一下 tf2onnx 这个库。

stricklandye avatar Feb 06 '24 15:02 stricklandye

I looked at the inference code and did not consider the input NC4HW4 layout. When converting the mnn model, add --keepInputFormat. After testing and adding this option, the inference results were normal using the original code.

Hey i am also facing a similar issue. Can you please explain what --keepInputFormat flag does and how is it related to input NC4HW4 layout. Thanks

Yash-Vardhan-Sharma avatar Feb 16 '24 12:02 Yash-Vardhan-Sharma

@jxt1234 感谢社区的帮助,TF的推理差异是我有一个细微的地方代码写错。经过验证以后,准确率无误,--keepInputFormat也解决了跳变的问题。 再次感谢,我将 issue关了。

stricklandye avatar Feb 22 '24 07:02 stricklandye