MXNet 中的几个数据集

from mxnet import gluon
def transform(data, label):
    return data.astype('float32') / 255., label.astype('float32')

mnist_train = gluon.data.vision.MNIST(train= True, transform= transform)
mnist_test = gluon.data.vision.MNIST(train= False, transform= transform)
C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:118: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  label = np.fromstring(fin.read(), dtype=np.uint8).astype(np.int32)
C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:122: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  data = np.fromstring(fin.read(), dtype=np.uint8)

下载几个数据集到本地磁盘

cifar_100

cifar_100_train = gluon.data.vision.CIFAR100(root= 'E:/Data/MXNet/cifar100')
cifar_100_test = gluon.data.vision.CIFAR100(root= 'E:/Data/MXNet/cifar100', train= False)

def show_images(images):
    n = images.shape[0]
    _, figs = plt.subplots(1, n, figsize=(15, 15))
    for i in range(n):
        figs[i].imshow(images[i].asnumpy())
        figs[i].axes.get_xaxis().set_visible(False)
        figs[i].axes.get_yaxis().set_visible(False)
    plt.show()

data, label = cifar_100_train[1: 9]
print(data.shape, label)
show_images(data)
Downloading E:/Data/MXNet/cifar100\cifar-100-binary.tar.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/cifar100/cifar-100-binary.tar.gz...


C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:252: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  data = np.fromstring(fin.read(), dtype=np.uint8).reshape(-1, 3072+2)


(8, 32, 32, 3) [15  4 14  1  5 18  3 10]

output_3_3.png-27.7kB

cifar-10

cifar_10_train = gluon.data.vision.CIFAR10(root= 'E:/Data/MXNet/cifar10')
cifar_10_test = gluon.data.vision.CIFAR10(root= 'E:/Data/MXNet/cifar10', train= False)

def show_images(images):
    n = images.shape[0]
    _, figs = plt.subplots(1, n, figsize=(15, 15))
    for i in range(n):
        figs[i].imshow(images[i].asnumpy())
        figs[i].axes.get_xaxis().set_visible(False)
        figs[i].axes.get_yaxis().set_visible(False)
    plt.show()

data, label = cifar_10_train[1: 9]
print(data.shape, label)
show_images(data)
Downloading E:/Data/MXNet/cifar10\cifar-10-binary.tar.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/cifar10/cifar-10-binary.tar.gz...


C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:193: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  data = np.fromstring(fin.read(), dtype=np.uint8).reshape(-1, 3072+1)


(8, 32, 32, 3) [9 9 4 1 1 2 7 8]

output_4_3.png-31.3kB

mnist_train

mnist_train = gluon.data.vision.MNIST(root= 'E:/Data/MXNet/mnist')
mnist_test = gluon.data.vision.MNIST(root= 'E:/Data/MXNet/mnist', train= False)

def show_images(images):
    n = images.shape[0]
    _, figs = plt.subplots(1, n, figsize=(15, 15))
    for i in range(n):
        figs[i].imshow(images[i].reshape((28, 28)).asnumpy())
        figs[i].axes.get_xaxis().set_visible(False)
        figs[i].axes.get_yaxis().set_visible(False)
    plt.show()

data, label = mnist_train[1: 9]
print(data.shape, label)
show_images(data)
Downloading E:/Data/MXNet/mnist\train-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/mnist/train-images-idx3-ubyte.gz...
Downloading E:/Data/MXNet/mnist\train-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/mnist/train-labels-idx1-ubyte.gz...


C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:118: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  label = np.fromstring(fin.read(), dtype=np.uint8).astype(np.int32)
C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:122: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  data = np.fromstring(fin.read(), dtype=np.uint8)


Downloading E:/Data/MXNet/mnist\t10k-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/mnist/t10k-images-idx3-ubyte.gz...
Downloading E:/Data/MXNet/mnist\t10k-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/mnist/t10k-labels-idx1-ubyte.gz...
(8, 28, 28, 1) [0 4 1 9 2 1 3 1]

output_5_3.png-6.1kB

Fashion-MNIST

fashion_mnist_train = gluon.data.vision.FashionMNIST(root= 'E:/Data/MXNet/fashion_mnist')
fashion_mnist_test = gluon.data.vision.FashionMNIST(root= 'E:/Data/MXNet/fashion_mnist', train= False)

def show_images(images):
    n = images.shape[0]
    _, figs = plt.subplots(1, n, figsize=(15, 15))
    for i in range(n):
        figs[i].imshow(images[i].reshape((28, 28)).asnumpy())
        figs[i].axes.get_xaxis().set_visible(False)
        figs[i].axes.get_yaxis().set_visible(False)
    plt.show()

def get_text_labels(label):
    text_labels = [
        't-shirt', 'trouser', 'pullover', 'dress,', 'coat',
        'sandal', 'shirt', 'sneaker', 'bag', 'ankle boot'
    ]
    return [text_labels[int(i)] for i in label]

data, label = fashion_mnist_train[0:9]
show_images(data)
print(get_text_labels(label))
Downloading E:/Data/MXNet/fashion_mnist\train-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-images-idx3-ubyte.gz...
Downloading E:/Data/MXNet/fashion_mnist\train-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz...


C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:118: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  label = np.fromstring(fin.read(), dtype=np.uint8).astype(np.int32)
C:\Anaconda3\lib\site-packages\mxnet\gluon\data\vision.py:122: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  data = np.fromstring(fin.read(), dtype=np.uint8)


Downloading E:/Data/MXNet/fashion_mnist\t10k-images-idx3-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/t10k-images-idx3-ubyte.gz...
Downloading E:/Data/MXNet/fashion_mnist\t10k-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/t10k-labels-idx1-ubyte.gz...

output_7_3.png-17.2kB

['pullover', 'ankle boot', 'shirt', 't-shirt', 'dress,', 'coat', 'coat', 'sandal', 'coat']
posted @ 2018-01-27 20:31  xinet  阅读(2534)  评论(0编辑  收藏  举报