Skip to content

Commit 9221826

Browse files
authored
Merge pull request #343 from wuyefeilin/release/v0.5.0
update infer.py
2 parents fb27c48 + 139ce8f commit 9221826

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

deploy/python/infer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ def __init__(self, configs):
115115
# image processing thread worker
116116
def process_worker(self, imgs, idx, use_pr=False):
117117
image_path = imgs[idx]
118-
im = cv2.imread(image_path, -1)
119-
if len(im.shape) == 2:
120-
im = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
118+
cv2_imread_flag = cv2.IMREAD_COLOR
119+
if self.config.channels == 4:
120+
cv2_imread_flag = cv2.IMREAD_UNCHANGED
121+
im = cv2.imread(image_path, cv2_imread_flag)
121122
channels = im.shape[2]
122123
if channels != 3 and channels != 4:
123124
print("Only support rgb(gray) or rgba image.")
@@ -133,8 +134,10 @@ def process_worker(self, imgs, idx, use_pr=False):
133134

134135
# if use models with no pre-processing/post-processing op optimizations
135136
if not use_pr:
136-
im_mean = np.array(self.config.mean).reshape((3, 1, 1))
137-
im_std = np.array(self.config.std).reshape((3, 1, 1))
137+
im_mean = np.array(self.config.mean).reshape((self.config.channels,
138+
1, 1))
139+
im_std = np.array(self.config.std).reshape((self.config.channels, 1,
140+
1))
138141
# HWC -> CHW, don't use transpose((2, 0, 1))
139142
im = im.swapaxes(1, 2)
140143
im = im.swapaxes(0, 1)

0 commit comments

Comments
 (0)