You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\anaconda3\envs\LID-CMC\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\anaconda3\envs\LID-CMC\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "D:\anaconda3\envs\LID-CMC\Scripts\x2paddle.exe_main.py", line 7, in
sys.exit(main())
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\convert.py", line 489, in main
onnx2paddle(
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\convert.py", line 304, in onnx2paddle
mapper = ONNXOpMapper(model)
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\onnx_op_mapper.py", line 52, in init
func(node)
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\opset_legacy.py", line 112, in run_mapping
raise Exception("convert failed node:{}, op_type is {}".format(
Exception: convert failed node:_features_conv0_Conv_output_0, op_type is Conv
错误截图
具体信息
详细代码
import torch,os
from torchvision.models.densenet import DenseNet121_Weights, DenseNet
# Initialize Result Path
input_tensor = torch.randn(64, 3, 224, 224)
output_folder = os.path.join(os.getcwd())
if not os.path.exists(output_folder):
os.makedirs(output_folder)
weights = DenseNet121_Weights.verify(None)
model = DenseNet(32, (6, 12, 24, 16), num_classes=100)
model_name = "densenet121"
if weights is not None:
model.load_state_dict(weights.get_state_dict(progress=True))
model.eval()
# 指定存储文件夹的名称
if not os.path.exists(os.path.join(output_folder, f"{model_name}_IR_and_pd")):
os.makedirs(os.path.join(output_folder, f"{model_name}_IR_and_pd"))
try:
import torch
except Exception as e:
raise ValueError(f"import torch failed:{e}")
onnx_file = os.path.join(output_folder, f"{model_name}_IR_and_pd", f"testTorch{model_name}.onnx")
try:
torch.onnx.export(model, input_tensor, onnx_file, verbose=True)
except Exception as e:
raise ValueError(f"Failed to export ONNX model: {e}")
pd_model_dir = os.path.join(output_folder, f"{model_name}_IR_and_pd")
# 使用 x2paddle 转换 ONNX 模型到 PaddlePaddle 格式
try:
conversion_command = f"x2paddle --framework=onnx --model={onnx_file} --save_dir={pd_model_dir}"
conversion_result = os.system(conversion_command)
print(f"x2paddle conversion command returned: {conversion_result}")
except Exception as e:
raise ValueError(f"Failed to convert ONNX model with x2paddle: {e}")
print(f"Model conversion completed. ONNX and PaddlePaddle models are saved in '{output_folder}'.")
感谢您参与 X2Paddle 社区! 问题模版为了 X2Paddle 能更好的迭代,例如新功能发布、 RoadMaps 和错误跟踪. 😸
问题描述
将PyTorch官方库中的DenseNet模型转换为Paddle版本,并用于测试基于ONNX的模型转换性能。PyTorch模型转换ONNX成功,但是ONNX转换为PaddlePaddle失败
-Converting node 434 ... Traceback (most recent call last):
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\opset_legacy.py", line 110, in run_mapping
res = func(*args, **kwargs)
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\opset_legacy.py", line 2304, in Conv
_rename_or_remove_weight(
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\opset_legacy.py", line 68, in _rename_or_remove_weight
raise KeyError('{} not a key in {}'.format(origin_name, weights.keys()))
KeyError: "x2paddle_onnx__Conv_1167 not a key in dict_keys(['x2paddle_features_denseblock1_denselayer1_norm1_weight', 'x2paddle_features_denseblock1_denselayer1_norm1_bias', 'x2paddle_features_denseblock1_denselayer1_conv2_weight', 'x2paddle_features_denseblock1_denselayer2_norm1_weight', 'x2paddle_features_denseblock1_denselayer2_norm1_bias', 'x2paddle_features_denseblock1_denselayer2_conv2_weight', 'x2paddle_features_denseblock1_denselayer3_norm1_weight', 'x2paddle_features_denseblock1_denselayer3_norm1_bias', 'x2paddle_features_denseblock1_denselayer3_conv2_weight', 'x2paddle_features_denseblock1_denselayer4_norm1_weight', 'x2paddle_features_denseblock1_denselayer4_norm1_bias', 'x2paddle_features_denseblock1_denselayer4_conv2_weight', 'x2paddle_features_denseblock1_denselayer5_norm1_weight', 'x2paddle_features_denseblock1_denselayer5_norm1_bias', 'x2paddle_features_denseblock1_denselayer5_conv2_weight', 'x2paddle_features_denseblock1_denselayer6_norm1_weight', 'x2paddle_features_denseblock1_denselayer6_norm1_bias', 'x2paddle_features_denseblock1_denselayer6_conv2_weight', 'x2paddle_features_transition1_norm_weight', 'x2paddle_features_transition1_norm_bias', 'x2paddle_features_transition1_conv_weight', 'x2paddle_features_denseblock2_denselayer1_conv2_weight', 'x2paddle_features_denseblock2_denselayer2_conv2_weight', 'x2paddle_features_denseblock2_denselayer3_conv2_weight', 'x2paddle_features_denseblock2_denselayer4_conv2_weight', 'x2paddle_features_denseblock2_denselayer5_conv2_weight', 'x2paddle_features_denseblock2_denselayer6_norm1_weight', 'x2paddle_features_denseblock2_denselayer6_norm1_bias', 'x2paddle_features_denseblock2_denselayer6_conv2_weight', 'x2paddle_features_denseblock2_denselayer7_norm1_weight', 'x2paddle_features_denseblock2_denselayer7_norm1_bias', 'x2paddle_features_denseblock2_denselayer7_conv2_weight', 'x2paddle_features_denseblock2_denselayer8_norm1_weight', 'x2paddle_features_denseblock2_denselayer8_norm1_bias', 'x2paddle_features_denseblock2_denselayer8_conv2_weight', 'x2paddle_features_denseblock2_denselayer9_norm1_weight', 'x2paddle_features_denseblock2_denselayer9_norm1_bias', 'x2paddle_features_denseblock2_denselayer9_conv2_weight', 'x2paddle_features_denseblock2_denselayer10_norm1_weight', 'x2paddle_features_denseblock2_denselayer10_norm1_bias', 'x2paddle_features_denseblock2_denselayer10_conv2_weight', 'x2paddle_features_denseblock2_denselayer11_norm1_weight', 'x2paddle_features_denseblock2_denselayer11_norm1_bias', 'x2paddle_features_denseblock2_denselayer11_conv2_weight', 'x2paddle_features_denseblock2_denselayer12_norm1_weight', 'x2paddle_features_denseblock2_denselayer12_norm1_bias', 'x2paddle_features_denseblock2_denselayer12_conv2_weight', 'x2paddle_features_transition2_norm_weight', 'x2paddle_features_transition2_norm_bias', 'x2paddle_features_transition2_conv_weight', 'x2paddle_features_denseblock3_denselayer1_conv2_weight', 'x2paddle_features_denseblock3_denselayer2_conv2_weight', 'x2paddle_features_denseblock3_denselayer3_conv2_weight', 'x2paddle_features_denseblock3_denselayer4_conv2_weight', 'x2paddle_features_denseblock3_denselayer5_conv2_weight', 'x2paddle_features_denseblock3_denselayer6_conv2_weight', 'x2paddle_features_denseblock3_denselayer7_conv2_weight', 'x2paddle_features_denseblock3_denselayer8_conv2_weight', 'x2paddle_features_denseblock3_denselayer9_conv2_weight', 'x2paddle_features_denseblock3_denselayer10_norm1_weight', 'x2paddle_features_denseblock3_denselayer10_norm1_bias', 'x2paddle_features_denseblock3_denselayer10_conv2_weight', 'x2paddle_features_denseblock3_denselayer11_norm1_weight', 'x2paddle_features_denseblock3_denselayer11_norm1_bias', 'x2paddle_features_denseblock3_denselayer11_conv2_weight', 'x2paddle_features_denseblock3_denselayer12_norm1_weight', 'x2paddle_features_denseblock3_denselayer12_norm1_bias', 'x2paddle_features_denseblock3_denselayer12_conv2_weight', 'x2paddle_features_denseblock3_denselayer13_norm1_weight', 'x2paddle_features_denseblock3_denselayer13_norm1_bias', 'x2paddle_features_denseblock3_denselayer13_conv2_weight', 'x2paddle_features_denseblock3_denselayer14_norm1_weight', 'x2paddle_features_denseblock3_denselayer14_norm1_bias', 'x2paddle_features_denseblock3_denselayer14_conv2_weight', 'x2paddle_features_denseblock3_denselayer15_norm1_weight', 'x2paddle_features_denseblock3_denselayer15_norm1_bias', 'x2paddle_features_denseblock3_denselayer15_conv2_weight', 'x2paddle_features_denseblock3_denselayer16_norm1_weight', 'x2paddle_features_denseblock3_denselayer16_norm1_bias', 'x2paddle_features_denseblock3_denselayer16_conv2_weight', 'x2paddle_features_denseblock3_denselayer17_norm1_weight', 'x2paddle_features_denseblock3_denselayer17_norm1_bias', 'x2paddle_features_denseblock3_denselayer17_conv2_weight', 'x2paddle_features_denseblock3_denselayer18_norm1_weight', 'x2paddle_features_denseblock3_denselayer18_norm1_bias', 'x2paddle_features_denseblock3_denselayer18_conv2_weight', 'x2paddle_features_denseblock3_denselayer19_norm1_weight', 'x2paddle_features_denseblock3_denselayer19_norm1_bias', 'x2paddle_features_denseblock3_denselayer19_conv2_weight', 'x2paddle_features_denseblock3_denselayer20_norm1_weight', 'x2paddle_features_denseblock3_denselayer20_norm1_bias', 'x2paddle_features_denseblock3_denselayer20_conv2_weight', 'x2paddle_features_denseblock3_denselayer21_norm1_weight', 'x2paddle_features_denseblock3_denselayer21_norm1_bias', 'x2paddle_features_denseblock3_denselayer21_conv2_weight', 'x2paddle_features_denseblock3_denselayer22_norm1_weight', 'x2paddle_features_denseblock3_denselayer22_norm1_bias', 'x2paddle_features_denseblock3_denselayer22_conv2_weight', 'x2paddle_features_denseblock3_denselayer23_norm1_weight', 'x2paddle_features_denseblock3_denselayer23_norm1_bias', 'x2paddle_features_denseblock3_denselayer23_conv2_weight', 'x2paddle_features_denseblock3_denselayer24_norm1_weight', 'x2paddle_features_denseblock3_denselayer24_norm1_bias', 'x2paddle_features_denseblock3_denselayer24_conv2_weight', 'x2paddle_features_transition3_norm_weight', 'x2paddle_features_transition3_norm_bias', 'x2paddle_features_transition3_conv_weight', 'x2paddle_features_denseblock4_denselayer1_conv2_weight', 'x2paddle_features_denseblock4_denselayer2_conv2_weight', 'x2paddle_features_denseblock4_denselayer3_conv2_weight', 'x2paddle_features_denseblock4_denselayer4_conv2_weight', 'x2paddle_features_denseblock4_denselayer5_conv2_weight', 'x2paddle_features_denseblock4_denselayer6_conv2_weight', 'x2paddle_features_denseblock4_denselayer7_conv2_weight', 'x2paddle_features_denseblock4_denselayer8_conv2_weight', 'x2paddle_features_denseblock4_denselayer9_conv2_weight', 'x2paddle_features_denseblock4_denselayer10_conv2_weight', 'x2paddle_features_denseblock4_denselayer11_conv2_weight', 'x2paddle_features_denseblock4_denselayer12_conv2_weight', 'x2paddle_features_denseblock4_denselayer13_conv2_weight', 'x2paddle_features_denseblock4_denselayer14_conv2_weight', 'x2paddle_features_denseblock4_denselayer15_conv2_weight', 'x2paddle_features_denseblock4_denselayer16_conv2_weight', 'x2paddle_classifier_weight', 'x2paddle_classifier_bias', 'x2paddle_onnx__Conv_1166', 'x2paddle_onnx__Conv_1169', 'x2paddle_onnx__Conv_1172', 'x2paddle_onnx__Conv_1175', 'x2paddle_onnx__Conv_1178', 'x2paddle_onnx__Conv_1181', 'x2paddle_onnx__Conv_1184', 'x2paddle_onnx__Conv_1187', 'x2paddle_onnx__Conv_1190', 'x2paddle_onnx__Conv_1193', 'x2paddle_onnx__Conv_1196', 'x2paddle_onnx__Conv_1199', 'x2paddle_onnx__Conv_1202', 'x2paddle_onnx__Conv_1205', 'x2paddle_onnx__Conv_1208', 'x2paddle_onnx__Conv_1211', 'x2paddle_onnx__Conv_1214', 'x2paddle_onnx__Conv_1217', 'x2paddle_onnx__Conv_1220', 'x2paddle_onnx__Conv_1223', 'x2paddle_onnx__Conv_1226', 'x2paddle_onnx__Conv_1229', 'x2paddle_onnx__Conv_1232', 'x2paddle_onnx__Conv_1235', 'x2paddle_onnx__Conv_1238', 'x2paddle_onnx__Conv_1241', 'x2paddle_onnx__Conv_1244', 'x2paddle_onnx__Conv_1247', 'x2paddle_onnx__Conv_1250', 'x2paddle_onnx__Conv_1253', 'x2paddle_onnx__Conv_1256', 'x2paddle_onnx__Conv_1259', 'x2paddle_onnx__Conv_1262', 'x2paddle_onnx__Conv_1265', 'x2paddle_onnx__Conv_1268', 'x2paddle_onnx__Conv_1271', 'x2paddle_onnx__Conv_1274', 'x2paddle_onnx__Conv_1277', 'x2paddle_onnx__Conv_1280', 'x2paddle_onnx__Conv_1283', 'x2paddle_onnx__Conv_1286', 'x2paddle_onnx__Conv_1289', 'x2paddle_onnx__Conv_1292', 'x2paddle_onnx__Conv_1295', 'x2paddle_onnx__Conv_1298', 'x2paddle_onnx__Conv_1301', 'x2paddle_onnx__Conv_1304', 'x2paddle_onnx__Conv_1307', 'x2paddle_onnx__Conv_1310', 'x2paddle_onnx__Conv_1313', 'x2paddle_onnx__Conv_1316', 'x2paddle_onnx__Conv_1319', 'x2paddle_onnx__Conv_1322', 'x2paddle_onnx__Conv_1325', 'x2paddle_onnx__Conv_1328', 'x2paddle_onnx__Conv_1331', 'x2paddle_onnx__Conv_1334', 'x2paddle_onnx__Conv_1337', 'x2paddle_onnx__Conv_1340', 'x2paddle__features_transition1_pool_Constant_output_0', 'x2paddle__features_transition2_pool_Constant_output_0', 'x2paddle__features_transition3_pool_Constant_output_0', 'conv0.weight'])"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\anaconda3\envs\LID-CMC\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\anaconda3\envs\LID-CMC\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "D:\anaconda3\envs\LID-CMC\Scripts\x2paddle.exe_main.py", line 7, in
sys.exit(main())
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\convert.py", line 489, in main
onnx2paddle(
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\convert.py", line 304, in onnx2paddle
mapper = ONNXOpMapper(model)
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\onnx_op_mapper.py", line 52, in init
func(node)
File "D:\anaconda3\envs\LID-CMC\lib\site-packages\x2paddle\op_mapper\onnx2paddle\opset_legacy.py", line 112, in run_mapping
raise Exception("convert failed node:{}, op_type is {}".format(
Exception: convert failed node:_features_conv0_Conv_output_0, op_type is Conv
具体信息
详细代码
转换模型后用处
使用 Paddle 框架/ PaddleInference 推理预测
模型来源
densenet121:https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
应用场景
用于测试模型转换任务
版本信息
X2Paddle => 1.4.1
torchvision => 0.15.2
来源框架版本(PyTorch/TF/ONNX/Caffe):
onxx => 1.15.0
Pytorch => 2.0.1
paddlepaddle-gpu => 2.6.0
您的联系方式(邮箱/微信/电话)
[email protected]
The text was updated successfully, but these errors were encountered: