diff --git a/modules/image/Image_gan/style_transfer/stylepro_artistic/data_feed.py b/modules/image/Image_gan/style_transfer/stylepro_artistic/data_feed.py index 00cbbe4e928367d3b4cdedaf28ff4858fe811cc7..963b6a78ce083bb2b3ae6fbfb0b700b03f1670ce 100644 --- a/modules/image/Image_gan/style_transfer/stylepro_artistic/data_feed.py +++ b/modules/image/Image_gan/style_transfer/stylepro_artistic/data_feed.py @@ -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)) diff --git a/modules/image/Image_gan/style_transfer/stylepro_artistic/module.py b/modules/image/Image_gan/style_transfer/stylepro_artistic/module.py index b6739014d2f92eeabfa99d7993aa44e6dc0e8cf6..00106819387d273e9ec82de2d49791dedef2f508 100644 --- a/modules/image/Image_gan/style_transfer/stylepro_artistic/module.py +++ b/modules/image/Image_gan/style_transfer/stylepro_artistic/module.py @@ -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", diff --git a/modules/image/Image_gan/style_transfer/stylepro_artistic/processor.py b/modules/image/Image_gan/style_transfer/stylepro_artistic/processor.py index 62af41547cbb505576f6df4815d8a06711e83e0d..7f04b394f6e763503f335c7b75cb86090e94ad1b 100644 --- a/modules/image/Image_gan/style_transfer/stylepro_artistic/processor.py +++ b/modules/image/Image_gan/style_transfer/stylepro_artistic/processor.py @@ -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