• 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']
    
  • 相关阅读:
    如何找按钮数组在布局中的横竖坐标位置?
    java中使用rmi进行远程方法调用
    测试视频集,各种测试用的视频文件
    如何彻底禁用VS 2008的智能感知功能
    JavaScript秘密花园 Type Casting,undefined,eval,setTimeout,Auto Semicolon Insertion
    JavaScript秘密花园 scope, namespace, constructor, equality and comparisons
    造成内存位置访问无效的一个原因
    depends在VS2008消失了
    12月10日晚的月全食照片
    JavaScript秘密花园 Array, Array Constructor, for in loop, typeof, instanceOf
  • 原文地址:https://www.cnblogs.com/q735613050/p/8367158.html
Copyright © 2020-2023  润新知