MXNet 中的几个数据集

Posted q735613050

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]

技术分享图片

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]

技术分享图片

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]

技术分享图片

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...

技术分享图片

[‘pullover‘, ‘ankle boot‘, ‘shirt‘, ‘t-shirt‘, ‘dress,‘, ‘coat‘, ‘coat‘, ‘sandal‘, ‘coat‘]

以上是关于MXNet 中的几个数据集的主要内容,如果未能解决你的问题,请参考以下文章

VOC2012数据集取需要的几个类别

mxnet数据集的制作和训练

关于COM .net程序集,regasm,dll,tlb和guids的几个简短问题

使 PHP 代码更加简洁的几个小技巧

片段问题中的 NullPointerException

php中mysqli 处理查询结果集的几个方法