-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
PaddleDetection 导出GLF系列模型,使用生成配置文件 使用paddle推理单张图片或者paddle2onnx出的静态模型有shape错误的问题 #9234
Comments
请问你可以将代码使用
包围吗?代码有点儿长,并且因为没有被quote,其中的一部分被按照markdown语法渲染了,这增加了阅读的难度。如果可能的话,希望能够去除代码中没有用到的(例如被注释掉的)部分,以减少干扰。 |
import sys model=paddle.jit.load("/home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/model") img = img.astype('float32').transpose((2, 0, 1))#HWC to CHW img = np.expand_dims(img, axis=0) paddle.enable_static() out_name = 'multiclass_nms3_0.tmp_0' test = inference_program.block(0).var(out_name) x1 = np.array([[800, 1333]], 'float32') result = exe.run(inference_program, feed={feed_target_names[0]: img, feed_target_names[1]: x3}, fetch_list=[test]) print(result[0].shape) result[0].tofile(out_name+".bin") data = result[0].reshape((result[0].shape[0]*result[0].shape[1]),-1) |
我怀疑是paddleDetection导出模型的配置文件有问题,分辨率800x1333 可能不是正确的(x1和x3 的值,这个是post_process 你可以随便找个图片测试下) |
看起来确实是动转静的时候的input spec有问题。考虑到你使用的paddle detection版本有点儿早了(使用的是2.4,最新的是2.8),建议尝试使用最新的paddle版本(3.0.0b2)+最新的paddle detection版本重新导出~ |
最新的还是一样的,感觉像paddle detection的配置文件的问题,生成的yml配置文件是不是640x640 |
辛苦 @liu-jiaxuan 确认一下导出的input spec设置是否合适~ |
问题确认 Search before asking
Bug组件 Bug Component
No response
Bug描述 Describe the Bug
1、python3 tools/export_model.py -c configs/gfl/gfl_r18vd_1x_coco.yml -o weights=https://paddledet.bj.bcebos.com/models/gfl_r18vd_1x_coco.pdparams use_gpu=false
生成模型以及权重等参数,yml如下
2、paddleDetection 使用evl.py评估精度无问题不报错
3、使用paddle_run.py 脚本单张图片进行推理 出现shape不一致的问题
脚本如下
import sys
import paddle
import numpy as np
from PIL import Image
model=paddle.jit.load("/home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/model")
img = Image.open("/home/zhukun/zhukun/paddleDetection/PaddleDetection/dataset/voc/VOCdevkit/VOC2007/JPEGImages/009963.jpg").convert('RGB')
print(img.size)
img = img.resize((800, 1333), Image.BILINEAR)
img = np.array(img)
mean = [104, 117, 123]
norm = [1, 1, 1]
img = (img - mean) * norm
img = img.astype('float32').transpose((2, 0, 1))#HWC to CHW
print('img : ', img)
img = np.expand_dims(img, axis=0)
#x1 = paddle.to_tensor([[1024,1024]],dtype = "float32")
#x3 = paddle.to_tensor([[1,1]],dtype = "float32")
#predicts=model(img, x3)
#print(predicts[0])
#x1 = paddle.to_tensor([[640,640]],dtype = "float32")
#x3 = paddle.to_tensor([[1,1]],dtype = "float32")
#x1 = paddle.ones([1,2],'float32')
#x3 = paddle.ones([1,2],'float32')
data = predicts[0].numpy()
np.savetxt("data.txt", data, fmt='%.04f', delimiter='\n')
#model=paddle.jit.load("C:/Users/dell/Documents/paddle/DCN/faster_rcnn_dcn_r50_fpn_1x_coco/model")
paddle.enable_static()
exe = paddle.static.Executor(paddle.CPUPlace())
[inference_program, feed_target_names, fetch_targets] = (paddle.static.load_inference_model("/home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/model", exe))
#out_name = 'reshape2_95.tmp_0'
out_name = 'multiclass_nms3_0.tmp_0'
#out_name = 'top_k_v2_0.tmp_1'
#out_name = 'max_0.tmp_0'
#out_name = 'image'
test = inference_program.block(0).var(out_name)
#x1 = np.ones([1,2],'float32')
#x3 = np.ones([1,2],'float32')
x1 = np.array([[800, 1333]], 'float32')
x3 = np.array([[1.6, 2.13]], 'float32')
#result = exe.run(inference_program, feed={feed_target_names[0]: x1, feed_target_names[1]: img, feed_target_names[2]: x3}, fetch_list=[test])
result = exe.run(inference_program, feed={feed_target_names[0]: img, feed_target_names[1]: x3}, fetch_list=[test])
print("---- result value : ", result[0])
print(result[0].shape)
result[0].tofile(out_name+".bin")
for i in range(result[0].shape[0]):
for j in range(result[0].shape[1]):
print("idx : ", i * 6 + j , result[0][i, j].item())
data = result[0].reshape((result[0].shape[0]*result[0].shape[1]),-1)
np.savetxt("image.txt", data, delimiter='\n')
#x1 = paddle.to_tensor([[640,640]],dtype = "float32")
#x3 = paddle.to_tensor([[1,1]],dtype = "float32")
#model=paddle.jit.load("C:/Users/dell/Documents/paddle/PP-SMRT/ppyoloe_crn_x_300e_renche/model")
#predicts=model(img, x3)
#print(predicts[0])
错误:
Operands could not be broadcast together with the shape of X = [1, 256, 167, 100] and the shape of Y = [1, 256, 168, 100]. Received [167] in X is not equal to [168] in Y at i:2
4、使用paddle2onnx 生成onnx模型,打开add 算子的输入2个形状不一致
命令如下:
1) /home/zhukun/.local/bin/paddle2onnx --model_dir /home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/ --model_filename /home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/model.pdmodel --params_filename /home/zhukun/zhukun/paddleDetection/PaddleDetection/output_inference/gfl_r18vd_1x_coco/model.pdiparams --save_file ./output/gfl_r18vd_1x_coco.onnx
2)生成静态图
python3 -m paddle2onnx.optimize --input_model ./output/gfl_r18vd_1x_coco.onnx --output_model new_model.onnx --input_shape_dict "{'image':[1,3,800,1333]}"
复现环境 Environment
OS : linux paddlepaddle: 2.6 paddleDetection: 2.4 python 3.10 CPU
Bug描述确认 Bug description confirmation
是否愿意提交PR? Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: