基于paddle的模型部署

f3temu5u  于 5个月前  发布在  其他
关注(0)|答案(3)|浏览(98)

请提出你的问题 Please ask your question

aistudio中有个基于paddlepaddle的yolov5的复现,训练出的模型只有一个文件,是best,pdparams,后期如何导出部署?有教程或者文档吗。

k97glaaz

k97glaaz1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看 官网API文档常见问题历史IssueAI社区 来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

kh212irz

kh212irz2#

@fan-min-97 可以参考paddle官网的教程,进行动转静部署。 https://www.paddlepaddle.org.cn/tutorials/projectdetail/3714002

yzuktlbb

yzuktlbb3#

复现项目是这个。 https://aistudio.baidu.com/aistudio/projectdetail/2580805,在动转静的用于部署时:
执行代码:
import paddle
from yolo import *
from models.common import *
from models.experimental import *
from utils.autoanchor import check_anchor_order
from utils.general import check_version, check_yaml, make_divisible, print_args, LOGGER
from utils.plots import feature_visualization
from utils.paddle_utils import copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img,
select_device, time_sync

save inference model

from paddle.static import InputSpec

加载训练好的模型参数

model=Model()
state_dict = paddle.load("YOLOv5-Paddle/runs/train/exp8/weights/best.pdparams")

将训练好的参数读取到网络中

model.set_state_dict(state_dict)

设置模型为评估模式

model.eval()

保存inference模型

paddle.jit.save(
layer=model,
path="YOLOv5-Paddle/inference/helmet",
input_spec=[InputSpec(shape=[None, 640], dtype='float32')])

print("==>Inference model saved in YOLOv5-Paddle/inference/helmet.")

问题1:model=Model()这个model 在项目的YOLOv5_Paddle/models/yolo.py中定义的,是否这里有误?该如何定义这个model
问题2: input_spec=[InputSpec(shape=[None, 784], dtype='float32')]) 也不行,报错

报错:
ValueError: In transformed code:

File "/home/aistudio/YOLOv5-Paddle/models/yolo.py", line 128, in forward
return self._forward_once(x, profile, visualize)  # single-scale inference, train
File "/home/aistudio/YOLOv5-Paddle/models/yolo.py", line 151, in _forward_once
x = m(x)
File "/home/aistudio/YOLOv5-Paddle/models/common.py", line 85, in forward
    def forward(self, x):
        return self.act(self.bn(self.conv(x)))
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

    def forward_fuse(self, x):

File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 917, in __call__
return self._dygraph_call_func(*inputs, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 907, in _dygraph_call_func
outputs = self.forward(*inputs, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/conv.py", line 677, in forward
use_cudnn=self._use_cudnn)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/functional/conv.py", line 148, in _conv_nd
type=op_type, inputs=inputs, outputs=outputs, attrs=attrs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py", line 3184, in append_op
attrs=kwargs.get("attrs", None))
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2344, in __init__
self.desc.infer_shape(self.block.desc)

ValueError: (InvalidArgument) The input of Op(Conv) should be a 4-D or 5-D Tensor. But received: input's dimension is 2, input's shape is [-1, 640].

[Hint: Expected in_dims.size() == 4 || in_dims.size() == 5 == true, but received in_dims.size() == 4 || in_dims.size() == 5:0 != true:1.] (at /paddle/paddle/fluid/operators/conv_op.cc:74)
[operator < conv2d > error]

相关问题