forked from mindspore-Ecosystem/mindspore
!25560 Support bytes input for decode op
Merge pull request !25560 from luoyang/serving
This commit is contained in:
commit
958c2a8e00
|
@ -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