piiswrong closed pull request #10493: fix warnings from np.fromstring
URL: https://github.com/apache/incubator-mxnet/pull/10493
 
 
   

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/gluon/data/vision/datasets.py 
b/python/mxnet/gluon/data/vision/datasets.py
index 88c0258a8b1..74a5aebf17b 100644
--- a/python/mxnet/gluon/data/vision/datasets.py
+++ b/python/mxnet/gluon/data/vision/datasets.py
@@ -81,11 +81,11 @@ def _get_data(self):
 
         with gzip.open(label_file, 'rb') as fin:
             struct.unpack(">II", fin.read(8))
-            label = np.fromstring(fin.read(), dtype=np.uint8).astype(np.int32)
+            label = np.frombuffer(fin.read(), dtype=np.uint8).astype(np.int32)
 
         with gzip.open(data_file, 'rb') as fin:
             struct.unpack(">IIII", fin.read(16))
-            data = np.fromstring(fin.read(), dtype=np.uint8)
+            data = np.frombuffer(fin.read(), dtype=np.uint8)
             data = data.reshape(len(label), 28, 28, 1)
 
         self._data = nd.array(data, dtype=data.dtype)
@@ -160,7 +160,7 @@ def __init__(self, root=os.path.join('~', '.mxnet', 
'datasets', 'cifar10'),
 
     def _read_batch(self, filename):
         with open(filename, 'rb') as fin:
-            data = np.fromstring(fin.read(), dtype=np.uint8).reshape(-1, 
3072+1)
+            data = np.frombuffer(fin.read(), dtype=np.uint8).reshape(-1, 
3072+1)
 
         return data[:, 1:].reshape(-1, 3, 32, 32).transpose(0, 2, 3, 1), \
                data[:, 0].astype(np.int32)
@@ -222,7 +222,7 @@ def __init__(self, root=os.path.join('~', '.mxnet', 
'datasets', 'cifar100'),
 
     def _read_batch(self, filename):
         with open(filename, 'rb') as fin:
-            data = np.fromstring(fin.read(), dtype=np.uint8).reshape(-1, 
3072+2)
+            data = np.frombuffer(fin.read(), dtype=np.uint8).reshape(-1, 
3072+2)
 
         return data[:, 2:].reshape(-1, 3, 32, 32).transpose(0, 2, 3, 1), \
                data[:, 0+self._fine_label].astype(np.int32)
diff --git a/python/mxnet/recordio.py b/python/mxnet/recordio.py
index 7adb0b513e5..2ebe657accb 100644
--- a/python/mxnet/recordio.py
+++ b/python/mxnet/recordio.py
@@ -367,7 +367,7 @@ def unpack(s):
     header = IRHeader(*struct.unpack(_IR_FORMAT, s[:_IR_SIZE]))
     s = s[_IR_SIZE:]
     if header.flag > 0:
-        header = header._replace(label=np.fromstring(s, np.float32, 
header.flag))
+        header = header._replace(label=np.frombuffer(s, np.float32, 
header.flag))
         s = s[header.flag*4:]
     return header, s
 
diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py
index 91459de9d2a..d4d8ad29e24 100644
--- a/python/mxnet/test_utils.py
+++ b/python/mxnet/test_utils.py
@@ -1431,10 +1431,10 @@ def get_mnist():
     def read_data(label_url, image_url):
         with gzip.open(mx.test_utils.download(label_url)) as flbl:
             struct.unpack(">II", flbl.read(8))
-            label = np.fromstring(flbl.read(), dtype=np.int8)
+            label = np.frombuffer(flbl.read(), dtype=np.int8)
         with gzip.open(mx.test_utils.download(image_url), 'rb') as fimg:
             _, _, rows, cols = struct.unpack(">IIII", fimg.read(16))
-            image = np.fromstring(fimg.read(), 
dtype=np.uint8).reshape(len(label), rows, cols)
+            image = np.frombuffer(fimg.read(), 
dtype=np.uint8).reshape(len(label), rows, cols)
             image = image.reshape(image.shape[0], 1, 28, 
28).astype(np.float32)/255
         return (label, image)
 


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to