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

pytorch模型直接转TFLite可以支持动态维度输入吗? #73

Open
LinJinwhy opened this issue May 19, 2022 · 7 comments
Open

pytorch模型直接转TFLite可以支持动态维度输入吗? #73

LinJinwhy opened this issue May 19, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@LinJinwhy
Copy link

LinJinwhy commented May 19, 2022

因为有些模型的输入shape是不固定的,请问转换方法支持转出的TFLite模型是动态输入大小的吗?

@LinJinwhy LinJinwhy changed the title pytorch pytorch模型直接转TFLite可以支持动态维度输入吗? May 19, 2022
@peterjc123 peterjc123 added the enhancement New feature or request label May 19, 2022
@peterjc123
Copy link
Collaborator

peterjc123 commented May 19, 2022

据我所知,TFLite模型不支持动态输入大小,只能在AllocateTensors前用ResizeInput来一次性的改变输入的大小。如你有支持动态维度输入的TFLite模型,麻烦提供一个给我们,我们可以研究下怎么实现。

@zhiqwang
Copy link
Contributor

zhiqwang commented May 19, 2022

PyTorch 动态 shape 模型的话似乎必须要用 torch.jit.script 来导出?

@peterjc123
Copy link
Collaborator

PyTorch 动态 shape 模型的话似乎必须要用 torch.jit.script 来导出?

PyTorch这边其实无所谓,只要TFLite能支持,我们这边可以添加接口,通过一个pass来传播shape的动态性就可以了

@LinJinwhy
Copy link
Author

据我所知,TFLite模型不支持动态输入大小,只能在AllocateTensors前用ResizeInput来一次性的改变输入的大小。如你有支持动态维度输入的TFLite模型,麻烦提供一个给我们,我们可以研究下怎么实现。

您好,关于TFLite模型是否支持动态输入大小这个问题,我了解不深,只是参阅了 https://stackoverflow.com/questions/55701663/input-images-with-dynamic-dimensions-in-tensorflow-lite/55732431#55732431tensorflow/tensorflow#41807 这两个链接的回答

@peterjc123
Copy link
Collaborator

据我所知,TFLite模型不支持动态输入大小,只能在AllocateTensors前用ResizeInput来一次性的改变输入的大小。如你有支持动态维度输入的TFLite模型,麻烦提供一个给我们,我们可以研究下怎么实现。

您好,关于TFLite模型是否支持动态输入大小这个问题,我了解不深,只是参阅了 https://stackoverflow.com/questions/55701663/input-images-with-dynamic-dimensions-in-tensorflow-lite/55732431#55732431tensorflow/tensorflow#41807 这两个链接的回答

你试下你的模型走resize_input_tensor可以正常工作吗?

@LinJinwhy
Copy link
Author

据我所知,TFLite模型不支持动态输入大小,只能在AllocateTensors前用ResizeInput来一次性的改变输入的大小。如你有支持动态维度输入的TFLite模型,麻烦提供一个给我们,我们可以研究下怎么实现。

您好,关于TFLite模型是否支持动态输入大小这个问题,我了解不深,只是参阅了 https://stackoverflow.com/questions/55701663/input-images-with-dynamic-dimensions-in-tensorflow-lite/55732431#55732431tensorflow/tensorflow#41807 这两个链接的回答

你试下你的模型走resize_input_tensor可以正常工作吗?

会出现类似这样的问题: RuntimeError: tensorflow/lite/kernels/reshape.cc:66 num_input_elements != num_output_elements (10519065 != 51300000) Node number 0 (RESHAPE) failed to prepare. (截取自 https://discuss.tf.wiki/t/topic/303)

@peterjc123
Copy link
Collaborator

peterjc123 commented May 19, 2022

嗯,那reshape算子都得特殊处理下,你看下导出的torchscript包不包含shape相关的操作?如果有相关操作的话,我们只需要把shape跟踪下来就行了,如果没有就比较复杂了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants