forked from mindspore-Ecosystem/mindspore
Support bytes input for decode op
This commit is contained in:
parent
c3ce9c56c6
commit
b47ac46e92
|
@ -432,7 +432,9 @@ class Decode(ImageTensorOperation):
|
|||
Returns:
|
||||
img (NumPy), Decoded image.
|
||||
"""
|
||||
if not isinstance(img, np.ndarray) or img.ndim != 1 or img.dtype.type is np.str_:
|
||||
if isinstance(img, bytes):
|
||||
img = np.frombuffer(img, np.uint8)
|
||||
elif not isinstance(img, np.ndarray) or img.ndim != 1 or img.dtype.type is np.str_:
|
||||
raise TypeError(
|
||||
"Input should be an encoded image in 1-D NumPy format, got {}.".format(type(img)))
|
||||
return super().__call__(img)
|
||||
|
|
|
@ -25,9 +25,15 @@ def test_eager_decode():
|
|||
|
||||
img = C.Decode()(img)
|
||||
logger.info("Image.type: {}, Image.shape: {}".format(type(img), img.shape))
|
||||
|
||||
assert img.shape == (2268, 4032, 3)
|
||||
|
||||
fp = open("../data/dataset/apple.jpg", "rb")
|
||||
img2 = fp.read()
|
||||
|
||||
img2 = C.Decode()(img2)
|
||||
logger.info("Image.type: {}, Image.shape: {}".format(type(img2), img2.shape))
|
||||
assert img2.shape == (2268, 4032, 3)
|
||||
|
||||
|
||||
def test_eager_resize():
|
||||
img = cv2.imread("../data/dataset/apple.jpg")
|
||||
|
|
Loading…
Reference in New Issue