未验证 提交 4266d75f 编写于 作者: C chenjian 提交者: GitHub

Fix stylepro artistic (#1566)

上级 df0fa786
......@@ -67,10 +67,19 @@ def _handle_single(im_path=None, im_arr=None):
Returns:
im (numpy.ndarray): preprocessed data, with shape (1, 3, 512, 512).
"""
im = None
if im_path is not None:
im = cv2.imread(im_path)[:, :, ::-1].astype(np.float32)
im = cv2.imread(im_path)
if im is None:
raise FileNotFoundError('Error: The file path "{}" may not exist or is not a valid image file, please provide a valid path.'.format(im_path))
else:
assert(len(im.shape) == 3, 'The input image shape should be [H, W, 3], but got {}'.format(im.shape))
assert(im.shape[2] == 3, 'The input image should have 3 channels, but got {}'.format(im.shape[2]))
im = im[:, :, ::-1].astype(np.float32) ### Image should have 3-channels, and BGR format is arranged by cv2, we should change it to RGB.
if im_arr is not None:
im = im_arr[:, :, ::-1].astype(np.float32)
if im is None:
raise ValueError('No image data is provided. Please check the input "images" and "paths".')
w, h = im.shape[1], im.shape[0]
im = cv2.resize(im, (512, 512), interpolation=cv2.INTER_LINEAR)
im = im.transpose((2, 0, 1))
......
......@@ -22,7 +22,7 @@ from stylepro_artistic.data_feed import reader
@moduleinfo(
name="stylepro_artistic",
version="1.0.1",
version="1.0.2",
type="cv/style_transfer",
summary="StylePro Artistic is an algorithm for Arbitrary image style, which is parameter-free, fast yet effective.",
author="baidu-bdl",
......
......@@ -40,7 +40,11 @@ def postprocess(im, output_dir, save_im_name, visualization, size):
os.makedirs(output_dir)
# save image
save_path = os.path.join(output_dir, save_im_name)
cv2.imwrite(save_path, im)
try:
cv2.imwrite(save_path, im)
print('Notice: an image has been proccessed and saved in path "{}".'.format(os.path.abspath(save_path)))
except Exception as e:
print('Exception {}: Fail to save output image in path "{}".'.format(e, os.path.abspath(save_path)))
result['save_path'] = save_path
return result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册