Closed cww97 closed 3 years ago
import paddle
from paddle import nn
from paddle.static import InputSpec
import paddle2onnx as p2o
class LinearNet(nn.Layer):
def __init__(self):
super(LinearNet, self).__init__()
self._linear = nn.Linear(784, 10)
def forward(self, x):
return self._linear(x)
layer = LinearNet()
# configure model inputs
x_spec = InputSpec([None, 784], 'float32', 'x')
# convert model to inference mode
layer.eval()
save_path = 'onnx.save/linear_net'
# p2o.dygraph2onnx(layer, save_path + '.onnx', input_spec=[x_spec])
# when you paddlepaddle>2.0.0, you can try:
paddle.onnx.export(layer, save_path, input_spec=[x_spec])
出来结果,直接copy的这一段
python tut.py
Inference models that PaddleClas provides are listed as follows:
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Series | Name |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| AlexNet | AlexNet |
| DarkNet | DarkNet53 |
| DeiT | DeiT_base_distilled_patch16_224 DeiT_base_distilled_patch16_384 DeiT_base_patch16_224 DeiT_base_patch16_384 DeiT_small_distilled_patch16_224 |
| | DeiT_small_patch16_224 DeiT_tiny_distilled_patch16_224 DeiT_tiny_patch16_224 |
| DenseNet | DenseNet121 DenseNet161 DenseNet169 DenseNet201 DenseNet264 |
| DPN | DPN68 DPN92 DPN98 DPN107 DPN131 |
| EfficientNet | EfficientNetB0 EfficientNetB0_small EfficientNetB1 EfficientNetB2 EfficientNetB3 EfficientNetB4 EfficientNetB5 EfficientNetB6 EfficientNetB7 |
| GhostNet | GhostNet_x0_5 GhostNet_x1_0 GhostNet_x1_3 GhostNet_x1_3_ssld |
| HRNet | HRNet_W18_C HRNet_W30_C HRNet_W32_C HRNet_W40_C HRNet_W44_C HRNet_W48_C HRNet_W64_C HRNet_W18_C_ssld HRNet_W48_C_ssld |
| Inception | GoogLeNet InceptionV3 InceptionV4 |
| MobileNetV1 | MobileNetV1_x0_25 MobileNetV1_x0_5 MobileNetV1_x0_75 MobileNetV1 MobileNetV1_ssld |
| MobileNetV2 | MobileNetV2_x0_25 MobileNetV2_x0_5 MobileNetV2_x0_75 MobileNetV2 MobileNetV2_x1_5 MobileNetV2_x2_0 MobileNetV2_ssld |
| MobileNetV3 | MobileNetV3_small_x0_35 MobileNetV3_small_x0_5 MobileNetV3_small_x0_75 MobileNetV3_small_x1_0 MobileNetV3_small_x1_25 MobileNetV3_large_x0_35 |
| | MobileNetV3_large_x0_5 MobileNetV3_large_x0_75 MobileNetV3_large_x1_0 MobileNetV3_large_x1_25 MobileNetV3_small_x1_0_ssld |
| | MobileNetV3_large_x1_0_ssld |
| RegNet | RegNetX_4GF |
| Res2Net | Res2Net50_14w_8s Res2Net50_26w_4s Res2Net50_vd_26w_4s Res2Net200_vd_26w_4s Res2Net101_vd_26w_4s Res2Net50_vd_26w_4s_ssld |
| | Res2Net101_vd_26w_4s_ssld Res2Net200_vd_26w_4s_ssld |
| ResNeSt | ResNeSt50 ResNeSt50_fast_1s1x64d |
| ResNet | ResNet18 ResNet18_vd ResNet34 ResNet34_vd ResNet50 ResNet50_vc ResNet50_vd ResNet50_vd_v2 ResNet101 ResNet101_vd ResNet152 ResNet152_vd |
| | ResNet200_vd ResNet34_vd_ssld ResNet50_vd_ssld ResNet50_vd_ssld_v2 ResNet101_vd_ssld Fix_ResNet50_vd_ssld_v2 ResNet50_ACNet_deploy |
| ResNeXt | ResNeXt50_32x4d ResNeXt50_vd_32x4d ResNeXt50_64x4d ResNeXt50_vd_64x4d ResNeXt101_32x4d ResNeXt101_vd_32x4d ResNeXt101_32x8d_wsl |
| | ResNeXt101_32x16d_wsl ResNeXt101_32x32d_wsl ResNeXt101_32x48d_wsl Fix_ResNeXt101_32x48d_wsl ResNeXt101_64x4d ResNeXt101_vd_64x4d |
| | ResNeXt152_32x4d ResNeXt152_vd_32x4d ResNeXt152_64x4d ResNeXt152_vd_64x4d |
| SENet | SENet154_vd SE_HRNet_W64_C_ssld SE_ResNet18_vd SE_ResNet34_vd SE_ResNet50_vd SE_ResNeXt50_32x4d SE_ResNeXt50_vd_32x4d SE_ResNeXt101_32x4d |
| ShuffleNetV2 | ShuffleNetV2_swish ShuffleNetV2_x0_25 ShuffleNetV2_x0_33 ShuffleNetV2_x0_5 ShuffleNetV2_x1_0 ShuffleNetV2_x1_5 ShuffleNetV2_x2_0 |
| SqueezeNet | SqueezeNet1_0 SqueezeNet1_1 |
| SwinTransformer | SwinTransformer_large_patch4_window7_224_22kto1k SwinTransformer_large_patch4_window12_384_22kto1k SwinTransformer_base_patch4_window7_224_22kto1k |
| | SwinTransformer_base_patch4_window12_384_22kto1k SwinTransformer_base_patch4_window12_384 SwinTransformer_base_patch4_window7_224 |
| | SwinTransformer_small_patch4_window7_224 SwinTransformer_tiny_patch4_window7_224 |
| VGG | VGG11 VGG13 VGG16 VGG19 |
| VisionTransformer | ViT_base_patch16_224 ViT_base_patch16_384 ViT_base_patch32_384 ViT_large_patch16_224 ViT_large_patch16_384 ViT_large_patch32_384 |
| | ViT_small_patch16_224 |
| Xception | Xception41 Xception41_deeplab Xception65 Xception65_deeplab Xception71 |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
Traceback (most recent call last):
File "tut.py", line 26, in <module>
paddle.onnx.export(layer, save_path, input_spec=[x_spec])
File "/root/anaconda3/lib/python3.8/site-packages/paddle/onnx/export.py", line 100, in export
p2o.dygraph2onnx(
AttributeError: module 'paddle2onnx' has no attribute 'dygraph2onnx'
请问你的paddle2onnx版本是多少,目前最新版本为v0.6
pip install paddle2onnx==0.6
请问你的paddle2onnx版本是多少,目前最新版本为v0.6
pip install paddle2onnx==0.6
❯ pip install paddle2onnx==0.6
Requirement already satisfied: paddle2onnx==0.6 in /root/anaconda3/lib/python3.8/site-packages (0.6)
其他版本, paddlepaddle 2.1.0 python3.8 centos 7
麻烦你把上面的代码加几行重新执行一下
import paddle
from paddle import nn
from paddle.static import InputSpec
import paddle2onnx as p2o
# 加这几行
print("======", p2o.__path__)
print("======", p2o.__version__)
class LinearNet(nn.Layer):
def __init__(self):
super(LinearNet, self).__init__()
self._linear = nn.Linear(784, 10)
def forward(self, x):
return self._linear(x)
layer = LinearNet()
# configure model inputs
x_spec = InputSpec([None, 784], 'float32', 'x')
# convert model to inference mode
layer.eval()
save_path = 'onnx.save/linear_net'
# p2o.dygraph2onnx(layer, save_path + '.onnx', input_spec=[x_spec])
# when you paddlepaddle>2.0.0, you can try:
paddle.onnx.export(layer, save_path, input_spec=[x_spec])
然后贴一下输出的日志看下
❯ python tut.py
Inference models that PaddleClas provides are listed as follows:
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Series | Name |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| AlexNet | AlexNet |
| DarkNet | DarkNet53 |
| DeiT | DeiT_base_distilled_patch16_224 DeiT_base_distilled_patch16_384 DeiT_base_patch16_224 DeiT_base_patch16_384 DeiT_small_distilled_patch16_224 |
| | DeiT_small_patch16_224 DeiT_tiny_distilled_patch16_224 DeiT_tiny_patch16_224 |
| DenseNet | DenseNet121 DenseNet161 DenseNet169 DenseNet201 DenseNet264 |
| DPN | DPN68 DPN92 DPN98 DPN107 DPN131 |
| EfficientNet | EfficientNetB0 EfficientNetB0_small EfficientNetB1 EfficientNetB2 EfficientNetB3 EfficientNetB4 EfficientNetB5 EfficientNetB6 EfficientNetB7 |
| GhostNet | GhostNet_x0_5 GhostNet_x1_0 GhostNet_x1_3 GhostNet_x1_3_ssld |
| HRNet | HRNet_W18_C HRNet_W30_C HRNet_W32_C HRNet_W40_C HRNet_W44_C HRNet_W48_C HRNet_W64_C HRNet_W18_C_ssld HRNet_W48_C_ssld |
| Inception | GoogLeNet InceptionV3 InceptionV4 |
| MobileNetV1 | MobileNetV1_x0_25 MobileNetV1_x0_5 MobileNetV1_x0_75 MobileNetV1 MobileNetV1_ssld |
| MobileNetV2 | MobileNetV2_x0_25 MobileNetV2_x0_5 MobileNetV2_x0_75 MobileNetV2 MobileNetV2_x1_5 MobileNetV2_x2_0 MobileNetV2_ssld |
| MobileNetV3 | MobileNetV3_small_x0_35 MobileNetV3_small_x0_5 MobileNetV3_small_x0_75 MobileNetV3_small_x1_0 MobileNetV3_small_x1_25 MobileNetV3_large_x0_35 |
| | MobileNetV3_large_x0_5 MobileNetV3_large_x0_75 MobileNetV3_large_x1_0 MobileNetV3_large_x1_25 MobileNetV3_small_x1_0_ssld |
| | MobileNetV3_large_x1_0_ssld |
| RegNet | RegNetX_4GF |
| Res2Net | Res2Net50_14w_8s Res2Net50_26w_4s Res2Net50_vd_26w_4s Res2Net200_vd_26w_4s Res2Net101_vd_26w_4s Res2Net50_vd_26w_4s_ssld |
| | Res2Net101_vd_26w_4s_ssld Res2Net200_vd_26w_4s_ssld |
| ResNeSt | ResNeSt50 ResNeSt50_fast_1s1x64d |
| ResNet | ResNet18 ResNet18_vd ResNet34 ResNet34_vd ResNet50 ResNet50_vc ResNet50_vd ResNet50_vd_v2 ResNet101 ResNet101_vd ResNet152 ResNet152_vd |
| | ResNet200_vd ResNet34_vd_ssld ResNet50_vd_ssld ResNet50_vd_ssld_v2 ResNet101_vd_ssld Fix_ResNet50_vd_ssld_v2 ResNet50_ACNet_deploy |
| ResNeXt | ResNeXt50_32x4d ResNeXt50_vd_32x4d ResNeXt50_64x4d ResNeXt50_vd_64x4d ResNeXt101_32x4d ResNeXt101_vd_32x4d ResNeXt101_32x8d_wsl |
| | ResNeXt101_32x16d_wsl ResNeXt101_32x32d_wsl ResNeXt101_32x48d_wsl Fix_ResNeXt101_32x48d_wsl ResNeXt101_64x4d ResNeXt101_vd_64x4d |
| | ResNeXt152_32x4d ResNeXt152_vd_32x4d ResNeXt152_64x4d ResNeXt152_vd_64x4d |
| SENet | SENet154_vd SE_HRNet_W64_C_ssld SE_ResNet18_vd SE_ResNet34_vd SE_ResNet50_vd SE_ResNeXt50_32x4d SE_ResNeXt50_vd_32x4d SE_ResNeXt101_32x4d |
| ShuffleNetV2 | ShuffleNetV2_swish ShuffleNetV2_x0_25 ShuffleNetV2_x0_33 ShuffleNetV2_x0_5 ShuffleNetV2_x1_0 ShuffleNetV2_x1_5 ShuffleNetV2_x2_0 |
| SqueezeNet | SqueezeNet1_0 SqueezeNet1_1 |
| SwinTransformer | SwinTransformer_large_patch4_window7_224_22kto1k SwinTransformer_large_patch4_window12_384_22kto1k SwinTransformer_base_patch4_window7_224_22kto1k |
| | SwinTransformer_base_patch4_window12_384_22kto1k SwinTransformer_base_patch4_window12_384 SwinTransformer_base_patch4_window7_224 |
| | SwinTransformer_small_patch4_window7_224 SwinTransformer_tiny_patch4_window7_224 |
| VGG | VGG11 VGG13 VGG16 VGG19 |
| VisionTransformer | ViT_base_patch16_224 ViT_base_patch16_384 ViT_base_patch32_384 ViT_large_patch16_224 ViT_large_patch16_384 ViT_large_patch32_384 |
| | ViT_small_patch16_224 |
| Xception | Xception41 Xception41_deeplab Xception65 Xception65_deeplab Xception71 |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
Traceback (most recent call last):
File "tut.py", line 7, in <module>
print("======", p2o.__path__)
AttributeError: module 'paddle2onnx' has no attribute '__path__'
我是不是装了个假的p2o
检查下你当前目录下,是不是有名称为paddle2onnx.py
的文件,或者是paddle2onnx
的目录
如若没有,则先卸载paddle2onnx后,重新安装试试
哈哈哈哈哈哈,没事了
我一开始建的python文件的文件名就叫paddle2onnx.py
,甚至还有个paddle2onnx.sh
我是呆子
https://github.com/PaddlePaddle/Paddle2ONNX/blob/release/0.6/README_zh.md 动态图,readme里面的example代码,“动态图模型导出”这一段,直接无法运行,有特殊的版本需求吗