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

tensorflow如何快速转ncnn #27

Closed
github-luffy opened this issue Jul 23, 2019 · 10 comments
Closed

tensorflow如何快速转ncnn #27

github-luffy opened this issue Jul 23, 2019 · 10 comments

Comments

@github-luffy
Copy link

有谁有办法转成ncnn模型嘛

@liguiyuan
Copy link

有谁有办法转成ncnn模型嘛

可以试下这两种方法:

  1. 使用 tf_coreml 和WinML Tool实现 pb -> .onnx ,然后再用ncnn里面的tools实现 onnx-> ncnn
    (参考链接: https://github.com/Tencent/ncnn/issues/5#issuecomment-472258072)
  2. 直接使用onnx的工具来把 pb-> onnx, 然后再ncnn tools 转为ncnn.
    (参考链接: https://github.com/onnx/tensorflow-onnx)

我尝试了这两个方法,方法1没成功,方法2能成功转onnx, 但onnx转ncnn会有些op不支持,你可以试一下。成功了告诉我一下哈~

@github-luffy
Copy link
Author

已经转换成ncnn,1.0系数的pfld在pc端40ms左右,0.25系数的pfld在pc端10多ms左右,但精度损失还蛮严重的,在速度和精度上可以折衷的还有什么好的办法嘛

@liguiyuan
Copy link

已经转换成ncnn,1.0系数的pfld在pc端40ms左右,0.25系数的pfld在pc端10多ms左右,但精度损失还蛮严重的,在速度和精度上可以折衷的还有什么好的办法嘛

请教一下你是怎么转成ncnn的,我折腾了好久还是不成功,有没有教程。精度方面0.25损失严重的话,你可以试下0.75,然后再使用量化,感觉这样会好点。

@github-luffy
Copy link
Author

用pytorch代码重新实现,然后转onnx,并最后转成ncnn。正在做量化中。。。

@liguiyuan
Copy link

还要用pytorch重新写,有点麻烦,后面我也试一下。

@lyyiangang
Copy link

可以考虑转换为MNN,阿里的一个开源库

@zys1994
Copy link

zys1994 commented Aug 22, 2019

@liguiyuan,@github-luffy 你们转的模型是自己训的吗

@github-luffy
Copy link
Author

@zys1994 模型训好后,转成ncnn的

@YuPeize
Copy link

YuPeize commented Sep 3, 2019

@liguiyuan 想问一下转onnx遇到这个问题是为啥呢...
`Traceback (most recent call last):
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 426, in import_graph_def
graph._c_graph, serialized, options) # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 0 of node pfld_inference/conv_1/BatchNorm/cond_1/AssignMovingAvg/Switch was passed float from pfld_inference/conv_1/BatchNorm/moving_mean:0 incompatible with expected float_ref.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tf2onnx/convert.py", line 161, in
main()
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tf2onnx/convert.py", line 116, in main
graph_def, inputs, outputs = loader.from_graphdef(args.graphdef, args.inputs, args.outputs)
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tf2onnx/loader.py", line 63, in from_graphdef
tf.import_graph_def(graph_def, name='')
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/ypz/anaconda3/envs/PFLD/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 430, in import_graph_def
raise ValueError(str(e))
ValueError: Input 0 of node pfld_inference/conv_1/BatchNorm/cond_1/AssignMovingAvg/Switch was passed float from pfld_inference/conv_1/BatchNorm/moving_mean:0 incompatible with expected float_ref.`

@AnthonyF333
Copy link

mark

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

6 participants