部署推理预测
11ssbbjj 发布于2021-03-26 浏览:599 回复:4
0
收藏
快速回复

模型为在paddle中使用源码训练得到的模型,保存为预测文件,在推理预测部署时出现如下问题;

在人脸检测中,不存在如下问题,而换了自己训练的模型yolov3,就出现错误如下错误

batch_image = np.array([data['image'] for data in batch_data])
print(47, batch_image)     # [[[[-0.015625 -0.1015625 -0.2109375 ... -0.3046875 -0.234375 -0.1015625] [-0.1328125 -0.21875 -0.3046875 ... -0.1796875 -0.171875 -0.015625 ] 。。。有内容 
batch_image = PaddleTensor(batch_image.astype('float32'))
print(48, batch_image)   #   (打印的结果):paddle.fluid.core_avx.PaddleTensor object at 0x00000010B8FE5C38>
data_out = self.predictor.run([batch_image])
print(56, data_out)  # [  ] 为空
confidences = data_out[0].as_ndarray()

出现了  File "F:/mycode/pythonProject/main.py", line 27, in
result, img = face_detector.face_detection(images=[image])

File "F:\mycode\pythonProject\model.py", line 88, in face_detection
confidences = data_out[0].as_ndarray()
IndexError: list index out of range

收藏
点赞
0
个赞
共4条回复 最后由11ssbbjj回复于2021-03-29
#411ssbbjj回复于2021-03-29

项目“Jeston Tx2 预测部署”共享链接(有效期三天):https://aistudio.baidu.com/studio/project/partial/verify/1719294/4f815971f0e14770b46a84c3b4456bdb

0
#3BryceLuminary回复于2021-03-27

您好,请问您能在AIStudio等环境下给一个能复现的情况我们测试一下吗?谢谢

0
#211ssbbjj回复于2021-03-26

补充 以上问题的: 

from __future__ import absolute_import
from __future__ import division

import numpy as np
import paddle.fluid as fluid
from paddle.fluid.core import PaddleTensor, AnalysisConfig, create_paddle_predictor

from processor import postprocess, base64_to_cv2
from data_feed import reader


class FaceDetector():
"""
predictor config setting
"""
config = AnalysisConfig("rat/model", "rat/params")
# config.disable_glog_info()
config.disable_gpu()

# config.enable_use_gpu(memory_pool_init_size_mb=1000, device_id=0)
# config.enable_tensorrt_engine(
# workspace_size = 1<<30,
# max_batch_size=1, min_subgraph_size=5,
# precision_mode=AnalysisConfig.Precision.Float32,
# use_static=True, use_calib_mode=False)

predictor = create_paddle_predictor(config)

def face_detection(self,
images=None,
paths=None,
data=None,
batch_size=1,
output_dir='face_detector_predict_output',
visualization=False,
confs_threshold=0.9,
iou_threshold=0.6):
"""
API for face detection.

Args:
images (list(numpy.ndarray)): images data, shape of each is [H, W, C]
paths (list[str]): The paths of images.
batch_size (int): batch size.
use_gpu (bool): Whether to use gpu.
output_dir (str): The path to store output images.
visualization (bool): Whether to save image or not.
confs_threshold (float): threshold for confidence coefficient.
iou_threshold (float): threshold for iou.

Returns:
res (list[dict()]): The result of face detection and save path of images.
"""

# compatibility with older versions
if data and 'image' in data:
if paths is None:
paths = []
paths += data['image']

# get all data
all_data = []
for yield_data in reader(images, paths):
all_data.append(yield_data)
print(44, all_data)

total_num = len(all_data)
print(45 , total_num)
loop_num = int(np.ceil(total_num / batch_size))
print(46, loop_num)

res = []
for iter_id in range(loop_num):
batch_data = list()
handle_id = iter_id * batch_size
for image_id in range(batch_size):
try:
batch_data.append(all_data[handle_id + image_id])
except:
pass
# feed batch image
batch_image = np.array([data['image'] for data in batch_data])
print(47, batch_image)
batch_image = PaddleTensor(batch_image.astype('float32'))
print(48, batch_image)
data_out = self.predictor.run([batch_image])
print(56, data_out)
confidences = data_out[0].as_ndarray()
boxes = data_out[1].as_ndarray()

# postprocess one by one
for i in range(len(batch_data)):
out, img = postprocess(
confidences=confidences[i],
boxes=boxes[i],
orig_im=batch_data[i]['orig_im'],
orig_im_shape=batch_data[i]['orig_im_shape'],
orig_im_path=batch_data[i]['orig_im_path'],
output_dir=output_dir,
visualization=visualization,
confs_threshold=confs_threshold,
iou_threshold=iou_threshold)
res.append(out)
return res, img

 

result, img = face_detector.face_detection(images=[image])

0
快速回复
TOP
切换版块