zhreshold closed pull request #10697: [MXNET-360]auto convert str to bytes in
img.imdecode when py3
URL: https://github.com/apache/incubator-mxnet/pull/10697
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/mxnet/image/image.py b/python/mxnet/image/image.py
index b4b9cc2f1c0..59ebcdd5f3f 100644
--- a/python/mxnet/image/image.py
+++ b/python/mxnet/image/image.py
@@ -21,6 +21,7 @@
from __future__ import absolute_import, print_function
+import sys
import os
import random
import logging
@@ -28,6 +29,7 @@
import warnings
import numpy as np
+
try:
import cv2
except ImportError:
@@ -133,6 +135,9 @@ def imdecode(buf, *args, **kwargs):
<NDArray 224x224x3 @cpu(0)>
"""
if not isinstance(buf, nd.NDArray):
+ if sys.version_info[0] == 3 and not isinstance(buf, (bytes,
np.ndarray)):
+ raise ValueError('buf must be of type bytes or numpy.ndarray,'
+ 'if you would like to input type str, please
convert to bytes')
buf = nd.array(np.frombuffer(buf, dtype=np.uint8), dtype=np.uint8)
return _internal._cvimdecode(buf, *args, **kwargs)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services