MXNet 中的几个数据集

简介: from mxnet import gluondef transform(data, label): return data.astype('float32') / 255., label.astype('float32')mnist_train = gluon.
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']
探寻有趣之事!
目录
相关文章
|
2月前
|
数据采集 TensorFlow 算法框架/工具
【大作业-03】手把手教你用tensorflow2.3训练自己的分类数据集
本教程详细介绍了如何使用TensorFlow 2.3训练自定义图像分类数据集,涵盖数据集收集、整理、划分及模型训练与测试全过程。提供完整代码示例及图形界面应用开发指导,适合初学者快速上手。[教程链接](https://www.bilibili.com/video/BV1rX4y1A7N8/),配套视频更易理解。
56 0
【大作业-03】手把手教你用tensorflow2.3训练自己的分类数据集
|
2月前
|
机器学习/深度学习 自然语言处理 监控
利用 PyTorch Lightning 搭建一个文本分类模型
利用 PyTorch Lightning 搭建一个文本分类模型
69 8
利用 PyTorch Lightning 搭建一个文本分类模型
|
6月前
|
机器学习/深度学习 人工智能 PyTorch
|
1月前
|
机器学习/深度学习 数据采集 TensorFlow
利用TensorFlow实现简单的图像分类模型
利用TensorFlow实现简单的图像分类模型
30 0
|
2月前
|
机器学习/深度学习 数据可视化 TensorFlow
使用TensorFlow构建一个简单的图像分类模型
【10月更文挑战第18天】使用TensorFlow构建一个简单的图像分类模型
71 1
|
4月前
|
机器学习/深度学习 数据采集 TensorFlow
使用TensorFlow进行模型训练:一次实战探索
【8月更文挑战第22天】本文通过实战案例详解使用TensorFlow进行模型训练的过程。首先确保已安装TensorFlow,接着预处理数据,包括加载、增强及归一化。然后利用`tf.keras`构建卷积神经网络模型,并配置训练参数。最后通过回调机制训练模型,并对模型性能进行评估。此流程为机器学习项目提供了一个实用指南。
|
7月前
|
机器学习/深度学习 数据可视化 PyTorch
利用PyTorch实现基于MNIST数据集的手写数字识别
利用PyTorch实现基于MNIST数据集的手写数字识别
148 2
|
存储 缓存 自然语言处理
几个常见的小技巧加快Pytorch训练速度
几个常见的小技巧加快Pytorch训练速度
609 0
几个常见的小技巧加快Pytorch训练速度
|
机器学习/深度学习 TensorFlow 算法框架/工具
【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)
【深度学习】基于tensorflow的小型物体识别训练(数据集:CIFAR-10)
364 0
|
机器学习/深度学习 TensorFlow 算法框架/工具
TensorFlow进行不同模型和数据集之间的迁移学习和模型微调
TensorFlow进行不同模型和数据集之间的迁移学习和模型微调
236 0
TensorFlow进行不同模型和数据集之间的迁移学习和模型微调
下一篇
DataWorks