Skip to content

Commit

Permalink
fix_deploy_python_infer (PaddlePaddle#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
yghstill committed Feb 20, 2021
1 parent 4cd1291 commit 3d22238
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions dygraph/deploy/python/infer.py
Expand Up @@ -23,7 +23,7 @@
import cv2
import numpy as np
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 paddle.inference import Config
from paddle.inference import create_predictor
Expand Down Expand Up @@ -196,22 +196,22 @@ def predict(self,
self.predictor.run()
output_names = self.predictor.get_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()
np_segms = self.predictor.get_output_handle(output_names[
np_score = self.predictor.get_output_handle(output_names[
2]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[
3]).copy_to_cpu()

t1 = time.time()
for i in range(repeats):
self.predictor.run()
output_names = self.predictor.get_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()
np_segms = self.predictor.get_output_handle(output_names[
np_score = self.predictor.get_output_handle(output_names[
2]).copy_to_cpu()
np_segms = self.predictor.get_output_handle(output_names[
3]).copy_to_cpu()
t2 = time.time()
ms = (t2 - t1) * 1000.0 / repeats
print("Inference: {} ms per batch image".format(ms))
Expand Down
8 changes: 4 additions & 4 deletions dygraph/deploy/python/preprocess.py
Expand Up @@ -38,7 +38,7 @@ def decode_image(im_file, im_info):
return im, im_info


class ResizeOp(object):
class Resize(object):
"""resize image by target_size and max_size
Args:
target_size (int): the target size of image
Expand Down Expand Up @@ -115,7 +115,7 @@ def generate_scale(self, im):
return im_scale_y, im_scale_x


class NormalizeImageOp(object):
class NormalizeImage(object):
"""normalize image
Args:
mean (list): im - mean
Expand Down Expand Up @@ -150,15 +150,15 @@ def __call__(self, im, im_info):
return im, im_info


class PermuteOp(object):
class Permute(object):
"""permute image
Args:
to_bgr (bool): whether convert RGB to BGR
channel_first (bool): whether convert HWC to CHW
"""

def __init__(self, ):
super(PermuteOp, self).__init__()
super(Permute, self).__init__()

def __call__(self, im, im_info):
"""
Expand Down
2 changes: 1 addition & 1 deletion dygraph/deploy/python/visualize.py
Expand Up @@ -173,7 +173,7 @@ def draw_segm(im,
clsid2color = {}
np_segms = np_segms.astype(np.uint8)
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:
continue

Expand Down
2 changes: 1 addition & 1 deletion dygraph/docs/tutorials/INSTALL_cn.md
Expand Up @@ -12,7 +12,7 @@

**环境需求:**

- PaddlePaddle 每日版本
- PaddlePaddle 2.0.1 或 PaddlePaddle release/2.0分支最新编译安装包
- OS 64位操作系统
- Python 3(3.5.1+/3.6/3.7),64位版本
- pip/pip3(9.0.1+),64位版本
Expand Down
4 changes: 2 additions & 2 deletions dygraph/ppdet/engine/export_utils.py
Expand Up @@ -52,7 +52,7 @@ def _parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
for st in sample_transforms[1:]:
for key, value in st.items():
p = {'type': key}
if key == 'ResizeOp':
if key == 'Resize':
if value.get('keep_ratio',
False) and image_shape[1] is not None:
max_size = max(image_shape[1:])
Expand All @@ -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]
for bt in batch_transforms:
for key, value in bt.items():
if key == 'PadBatchOp':
if key == 'PadBatch':
preprocess_list.append({'type': 'PadStride'})
preprocess_list[-1].update({
'stride': value['pad_to_stride']
Expand Down

0 comments on commit 3d22238

Please sign in to comment.