Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit d4991a0

Browse files
yajiedesignzhreshold
authored andcommitted
[MXNET-360]auto convert str to bytes in img.imdecode when py3 (#10697)
* change to friendly error message * fix lint * fix lint * fix lint * update raise message
1 parent 9f5c96e commit d4991a0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

python/mxnet/image/image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
from __future__ import absolute_import, print_function
2323

24+
import sys
2425
import os
2526
import random
2627
import logging
2728
import json
2829
import warnings
2930
import numpy as np
3031

32+
3133
try:
3234
import cv2
3335
except ImportError:
@@ -133,6 +135,9 @@ def imdecode(buf, *args, **kwargs):
133135
<NDArray 224x224x3 @cpu(0)>
134136
"""
135137
if not isinstance(buf, nd.NDArray):
138+
if sys.version_info[0] == 3 and not isinstance(buf, (bytes, np.ndarray)):
139+
raise ValueError('buf must be of type bytes or numpy.ndarray,'
140+
'if you would like to input type str, please convert to bytes')
136141
buf = nd.array(np.frombuffer(buf, dtype=np.uint8), dtype=np.uint8)
137142
return _internal._cvimdecode(buf, *args, **kwargs)
138143

0 commit comments

Comments
 (0)