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

Commit

Permalink
[MXNET-360]auto convert str to bytes in img.imdecode when py3 (#10697)
Browse files Browse the repository at this point in the history
* change to friendly error message

* fix lint

* fix lint

* fix lint

* update raise message
  • Loading branch information
yajiedesign authored and zhreshold committed Sep 21, 2018
1 parent 9f5c96e commit d4991a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/mxnet/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

from __future__ import absolute_import, print_function

import sys
import os
import random
import logging
import json
import warnings
import numpy as np


try:
import cv2
except ImportError:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d4991a0

Please sign in to comment.