未验证 提交 86d75e9e 编写于 作者: G Guanghua Yu 提交者: GitHub

fix_deploy_python_infer (#2233)

上级 e4909b55
...@@ -23,7 +23,7 @@ from PIL import Image ...@@ -23,7 +23,7 @@ from PIL import Image
import cv2 import cv2
import numpy as np import numpy as np
import paddle import paddle
from preprocess import preprocess, ResizeOp, NormalizeImageOp, PermuteOp, PadStride from preprocess import preprocess, Resize, NormalizeImage, Permute, PadStride
from visualize import visualize_box_mask from visualize import visualize_box_mask
from paddle.inference import Config from paddle.inference import Config
from paddle.inference import create_predictor from paddle.inference import create_predictor
...@@ -196,22 +196,22 @@ class DetectorSOLOv2(Detector): ...@@ -196,22 +196,22 @@ class DetectorSOLOv2(Detector):
self.predictor.run() self.predictor.run()
output_names = self.predictor.get_output_names() output_names = self.predictor.get_output_names()
np_label = self.predictor.get_output_handle(output_names[ np_label = self.predictor.get_output_handle(output_names[
0]).copy_to_cpu()
np_score = self.predictor.get_output_handle(output_names[
1]).copy_to_cpu() 1]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[ np_score = self.predictor.get_output_handle(output_names[
2]).copy_to_cpu() 2]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[
3]).copy_to_cpu()
t1 = time.time() t1 = time.time()
for i in range(repeats): for i in range(repeats):
self.predictor.run() self.predictor.run()
output_names = self.predictor.get_output_names() output_names = self.predictor.get_output_names()
np_label = self.predictor.get_output_handle(output_names[ np_label = self.predictor.get_output_handle(output_names[
0]).copy_to_cpu()
np_score = self.predictor.get_output_handle(output_names[
1]).copy_to_cpu() 1]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[ np_score = self.predictor.get_output_handle(output_names[
2]).copy_to_cpu() 2]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[
3]).copy_to_cpu()
t2 = time.time() t2 = time.time()
ms = (t2 - t1) * 1000.0 / repeats ms = (t2 - t1) * 1000.0 / repeats
print("Inference: {} ms per batch image".format(ms)) print("Inference: {} ms per batch image".format(ms))
......
...@@ -38,7 +38,7 @@ def decode_image(im_file, im_info): ...@@ -38,7 +38,7 @@ def decode_image(im_file, im_info):
return im, im_info return im, im_info
class ResizeOp(object): class Resize(object):
"""resize image by target_size and max_size """resize image by target_size and max_size
Args: Args:
target_size (int): the target size of image target_size (int): the target size of image
...@@ -115,7 +115,7 @@ class ResizeOp(object): ...@@ -115,7 +115,7 @@ class ResizeOp(object):
return im_scale_y, im_scale_x return im_scale_y, im_scale_x
class NormalizeImageOp(object): class NormalizeImage(object):
"""normalize image """normalize image
Args: Args:
mean (list): im - mean mean (list): im - mean
...@@ -150,7 +150,7 @@ class NormalizeImageOp(object): ...@@ -150,7 +150,7 @@ class NormalizeImageOp(object):
return im, im_info return im, im_info
class PermuteOp(object): class Permute(object):
"""permute image """permute image
Args: Args:
to_bgr (bool): whether convert RGB to BGR to_bgr (bool): whether convert RGB to BGR
...@@ -158,7 +158,7 @@ class PermuteOp(object): ...@@ -158,7 +158,7 @@ class PermuteOp(object):
""" """
def __init__(self, ): def __init__(self, ):
super(PermuteOp, self).__init__() super(Permute, self).__init__()
def __call__(self, im, im_info): def __call__(self, im, im_info):
""" """
......
...@@ -173,7 +173,7 @@ def draw_segm(im, ...@@ -173,7 +173,7 @@ def draw_segm(im,
clsid2color = {} clsid2color = {}
np_segms = np_segms.astype(np.uint8) np_segms = np_segms.astype(np.uint8)
for i in range(np_segms.shape[0]): for i in range(np_segms.shape[0]):
mask, score, clsid = np_segms[i], np_score[i], np_label[i] + 1 mask, score, clsid = np_segms[i], np_score[i], np_label[i]
if score < threshold: if score < threshold:
continue continue
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
**环境需求:** **环境需求:**
- PaddlePaddle 每日版本 - PaddlePaddle 2.0.1 或 PaddlePaddle release/2.0分支最新编译安装包
- OS 64位操作系统 - OS 64位操作系统
- Python 3(3.5.1+/3.6/3.7),64位版本 - Python 3(3.5.1+/3.6/3.7),64位版本
- pip/pip3(9.0.1+),64位版本 - pip/pip3(9.0.1+),64位版本
......
...@@ -52,7 +52,7 @@ def _parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape): ...@@ -52,7 +52,7 @@ def _parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
for st in sample_transforms[1:]: for st in sample_transforms[1:]:
for key, value in st.items(): for key, value in st.items():
p = {'type': key} p = {'type': key}
if key == 'ResizeOp': if key == 'Resize':
if value.get('keep_ratio', if value.get('keep_ratio',
False) and image_shape[1] is not None: False) and image_shape[1] is not None:
max_size = max(image_shape[1:]) max_size = max(image_shape[1:])
...@@ -65,7 +65,7 @@ def _parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape): ...@@ -65,7 +65,7 @@ def _parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
methods = [list(bt.keys())[0] for bt in batch_transforms] methods = [list(bt.keys())[0] for bt in batch_transforms]
for bt in batch_transforms: for bt in batch_transforms:
for key, value in bt.items(): for key, value in bt.items():
if key == 'PadBatchOp': if key == 'PadBatch':
preprocess_list.append({'type': 'PadStride'}) preprocess_list.append({'type': 'PadStride'})
preprocess_list[-1].update({ preprocess_list[-1].update({
'stride': value['pad_to_stride'] 'stride': value['pad_to_stride']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册