zoukankan      html  css  js  c++  java
  • 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:Anaconda3libsite-packagesmxnetgluondatavision.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:Anaconda3libsite-packagesmxnetgluondatavision.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/cifar100cifar-100-binary.tar.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/cifar100/cifar-100-binary.tar.gz...
    
    
    C:Anaconda3libsite-packagesmxnetgluondatavision.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/cifar10cifar-10-binary.tar.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/cifar10/cifar-10-binary.tar.gz...
    
    
    C:Anaconda3libsite-packagesmxnetgluondatavision.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	rain-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	rain-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/mnist/train-labels-idx1-ubyte.gz...
    
    
    C:Anaconda3libsite-packagesmxnetgluondatavision.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:Anaconda3libsite-packagesmxnetgluondatavision.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	10k-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	10k-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	rain-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	rain-labels-idx1-ubyte.gz from https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz...
    
    
    C:Anaconda3libsite-packagesmxnetgluondatavision.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:Anaconda3libsite-packagesmxnetgluondatavision.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	10k-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	10k-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']
    
  • 相关阅读:
    泛型通配符 ?
    算法:确定一个字符串的所有字符是否全都不同。假使不允许使用额外的数据结构
    Math类中常用方法
    很认真的聊一聊程序员的自我修养
    高性能最终一致性框架Ray之基本概念原理
    asp.net core VS goang web[修正篇]
    Asp.net core与golang web简单对比测试
    高性能Socket组件和RPC,让你像写本地代码一样开发网络应用和分布式程序
    .NET MVC 插件化框架支持原生MVC的Area和路由特性
    .NET MVC插件化开发框架源码(插件功能完善版)
  • 原文地址:https://www.cnblogs.com/q735613050/p/8367158.html
Copyright © 2011-2022 走看看