日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

记一次灵活的模型训练生成的pth转onnx文件失败

發布時間:2024/10/6 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记一次灵活的模型训练生成的pth转onnx文件失败 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼1

import torch import torchvision dummy_input = torch.randn(1, 3, 224, 224) model = torch.load(r'D:\***\swin_transformer_flower\weights\model---0.pth') model.eval() input_names = ["input"] output_names = ["output"] torch.onnx.export(model,dummy_input,"model---9.onnx",verbose=True,input_names=input_names,output_names=output_names)

出錯信息

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

參考:【已解決】Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

代碼2

import torch import torchvision device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") dummy_input = torch.randn(1, 3, 224, 224).to(device) model = torch.load(r'D:\***\swin_transformer_flower\weights\model---0.pth') model.eval() input_names = ["input"] output_names = ["output"] torch.onnx.export(model,dummy_input,"model---9.onnx",verbose=True,input_names=input_names,output_names=output_names)

出錯信息:

D:\***\swin_transformer_flower\model.py:117: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!pad_input = (H % self.patch_size[0] != 0) or (W % self.patch_size[1] != 0) D:\***\swin_transformer_flower\model.py:119: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!if pad_input: D:\***\swin_transformer_flower\model.py:461: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!Hp = int(np.ceil(H / self.window_size)) * self.window_size D:\***\swin_transformer_flower\model.py:462: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!Wp = int(np.ceil(W / self.window_size)) * self.window_size D:\***\swin_transformer_flower\model.py:357: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!assert L == H * W, "input feature has wrong size" D:\***\swin_transformer_flower\model.py:85: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!B = int(windows.shape[0] / (H * W / window_size / window_size)) D:\***\swin_transformer_flower\model.py:396: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!if pad_r > 0 or pad_b > 0: D:\***\swin_transformer_flower\model.py:161: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!assert L == H * W, "input feature has wrong size" D:\***\swin_transformer_flower\model.py:167: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!pad_input = (H % 2 == 1) or (W % 2 == 1) D:\***\swin_transformer_flower\model.py:168: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!if pad_input: Traceback (most recent call last):File "D:/***/swin_transformer_flower/測試.py", line 19, in <module>output_names=output_names)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\__init__.py", line 230, in exportcustom_opsets, enable_onnx_checker, use_external_data_format)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\utils.py", line 91, in exportuse_external_data_format=use_external_data_format)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\utils.py", line 639, in _exportdynamic_axes=dynamic_axes)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\utils.py", line 421, in _model_to_graphdynamic_axes=dynamic_axes, input_names=input_names)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\utils.py", line 203, in _optimize_graphgraph = torch._C._jit_pass_onnx(graph, operator_export_type)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\__init__.py", line 263, in _run_symbolic_functionreturn utils._run_symbolic_function(*args, **kwargs)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\utils.py", line 934, in _run_symbolic_functionreturn symbolic_fn(g, *inputs, **attrs)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\symbolic_opset9.py", line 1314, in index_putsym_help._onnx_opset_unsupported('index_put', 9, 11)File "C:\Users\deep\anaconda3\envs\swin\lib\site-packages\torch\onnx\symbolic_helper.py", line 192, in _onnx_opset_unsupported'opset {}. Please try opset version {}.'.format(op_name, current_opset, supported_opset)) RuntimeError: Unsupported: ONNX export of index_put in opset 9. Please try opset version 11.

代碼3

改為

import torch import torchvision device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") dummy_input = torch.randn(1, 3, 224, 224).to(device) model = torch.load(r'D:\***\swin_transformer_flower\weights\model---0.pth') model.eval() input_names = ["input"] output_names = ["output"] torch.onnx.export(model,dummy_input,"model---9.onnx",export_params=True,verbose=True,input_names=input_names,output_names=output_names,opset_version=11,keep_initializers_as_inputs=True)

出錯信息

D:\***\swin_transformer_flower\model.py:117: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!pad_input = (H % self.patch_size[0] != 0) or (W % self.patch_size[1] != 0) RuntimeError: Exporting the operator roll to ONNX opset version 11 is not supported. Please open a bug to request ONNX export support for the missing operator.

分析:

原因是訓練模型的代碼中好像是太多if else語句了(我的理解) 如果你用Pytorch定義的網絡結構太過于靈活,那么轉成ONNX的時候很有可能出錯。 這個報錯通常情況下是你的網絡結構中出現if else 語句。 最好不要這樣寫,能避免的話盡量避免。不要寫if else判斷語句。

以上分析參考:
1、https://www.codeleading.com/article/37523519244/
2、pytorch轉onnx遇到的一些問題
3、Pytorch轉ONNX采坑記:Converting a tensor to a Python boolean might cause the trace to be incorrect. We…
4、pytorch報錯Converting a tensor to a Python integer

哪位大佬會這道題或者也遇到過這種情況可否留言解答一下,萬分感謝!

總結

以上是生活随笔為你收集整理的记一次灵活的模型训练生成的pth转onnx文件失败的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成人性做爰aaa片免费看不忠 | 国产高清视频一区二区 | 三级黄色生活片 | 超碰成人久久 | 国产视频一二三 | 日日摸夜夜添夜夜添高潮喷水 | 亚洲午夜精品一区二区三区他趣 | 亚洲第一香蕉网 | 亚洲激情网站 | 日韩极品少妇 | 麻豆视频在线观看免费网站 | 在线xxxx | 人妻精品久久久久中文 | 国产色综合天天综合网 | 在线看福利影 | 少妇一级淫片免费放2 | 亚洲国产精品成人综合色在线婷婷 | 欧美精品一区二 | 高潮网 | 在线观看免费大片 | 欧美日韩一本 | 黄色资源在线播放 | 日本黄区免费视频观看 | 优优色影院 | 怡红院一区 | 国产一区二区在线免费观看视频 | 亚洲视频在线观看一区 | 成人依依网 | 欧美日韩中文字幕在线播放 | 色www国产亚洲阿娇 自拍一区在线 | jizz日本免费| 国产欧美日韩综合精品一区二区三区 | 97精品人妻一区二区三区香蕉 | 美女又爽又黄又免费 | 五月婷婷综合激情网 | 久久97视频 | 免费看a毛片 | 视频丨9l丨白浆 | 国产视频在线免费观看 | 精品国产无码在线 | 封神榜二在线高清免费观看 | 日本一区二区三区免费视频 | 不卡视频在线观看免费 | 色网站免费观看 | 亚洲日本中文 | 性毛片| 亚洲精品一区二区三区不卡 | 性囗交免费视频观看 | 一区久久 | 老太脱裤让老头玩ⅹxxxx | 肉丝超薄少妇一区二区三区 | 人人看人人草 | 欧日韩视频 | 欧美无马| 韩国中文字幕在线观看 | 欧美激情影音先锋 | 国产特级视频 | 青草热视频| 五月天狠狠干 | 尤物视频在线观看国产 | 久久久国产成人一区二区三区 | 日本福利在线 | 69re视频 | 四季av一区二区凹凸精品 | 欧美熟妇另类久久久久久不卡 | 日本久久视频 | 黄色一级免费片 | 囯产精品久久久久久 | 看一级黄色| 天堂在线中文在线 | 天堂av手机在线 | 久热中文字幕在线 | av网站亚洲 | www日日日 | 日日射日日操 | 日本黄色短片 | 日本理论中文字幕 | 成人性生交大片 | 国产一区视频在线播放 | 精品久久久久一区二区 | 欧美激情一区二区三区 | 欧美福利在线 | 亚洲黄色小说网 | 强公把我次次高潮hd | 强行挺进皇后紧窄湿润小说 | 国产叼嘿视频在线观看 | 天天操天天操天天射 | 精品亚洲乱码一区二区 | 日欧一级片| 国产日韩在线视频 | 亚洲一页 | 夜晚福利| 久久久成人精品视频 | 国产91国语对白在线 | 日韩激情网| 欧美一区高清 | 精品欧美一区二区精品少妇 | 熟妇高潮一区二区三区在线播放 | 亚洲中文无码av在线 |