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

[MXNET-360]auto convert str to bytes in img.imdecode when py3 #10697

Merged
merged 5 commits into from
Sep 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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