提交 44240d4d 编写于 作者: J JiabinYang

fix bug to avoid warning once import paddle.fluid

上级 482d297b
...@@ -36,11 +36,6 @@ import numpy as np ...@@ -36,11 +36,6 @@ import numpy as np
try: try:
import cv2 import cv2
except ImportError: except ImportError:
import sys
sys.stderr.write(
'''Warning with paddle image module: opencv-python should be imported,
or paddle image module could NOT work; please install opencv-python first.'''
)
cv2 = None cv2 = None
import os import os
import tarfile import tarfile
...@@ -53,6 +48,18 @@ __all__ = [ ...@@ -53,6 +48,18 @@ __all__ = [
] ]
def _check_cv2():
if cv2 is None:
import sys
sys.stderr.write(
'''Warning with paddle image module: opencv-python should be imported,
or paddle image module could NOT work; please install opencv-python first.'''
)
return False
else:
return True
def batch_images_from_tar(data_file, def batch_images_from_tar(data_file,
dataset_name, dataset_name,
img2label, img2label,
...@@ -134,7 +141,7 @@ def load_image_bytes(bytes, is_color=True): ...@@ -134,7 +141,7 @@ def load_image_bytes(bytes, is_color=True):
load and return a gray image. load and return a gray image.
:type is_color: bool :type is_color: bool
""" """
assert cv2 is not None assert _check_cv2() is True
flag = 1 if is_color else 0 flag = 1 if is_color else 0
file_bytes = np.asarray(bytearray(bytes), dtype=np.uint8) file_bytes = np.asarray(bytearray(bytes), dtype=np.uint8)
...@@ -159,7 +166,7 @@ def load_image(file, is_color=True): ...@@ -159,7 +166,7 @@ def load_image(file, is_color=True):
load and return a gray image. load and return a gray image.
:type is_color: bool :type is_color: bool
""" """
assert cv2 is not None assert _check_cv2() is True
# cv2.IMAGE_COLOR for OpenCV3 # cv2.IMAGE_COLOR for OpenCV3
# cv2.CV_LOAD_IMAGE_COLOR for older OpenCV Version # cv2.CV_LOAD_IMAGE_COLOR for older OpenCV Version
...@@ -188,7 +195,7 @@ def resize_short(im, size): ...@@ -188,7 +195,7 @@ def resize_short(im, size):
:param size: the shorter edge size of image after resizing. :param size: the shorter edge size of image after resizing.
:type size: int :type size: int
""" """
assert cv2 is not None assert _check_cv2() is True
h, w = im.shape[:2] h, w = im.shape[:2]
h_new, w_new = size, size h_new, w_new = size, size
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册