精华内容
下载资源
问答
  • Fashion MNIST

    2020-10-27 09:02:10
    Fashion MNIST An MNIST-like dataset of 70,000 28x28 labeled fashion images Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of ...

    原文:

    Fashion MNIST

    An MNIST-like dataset of 70,000 28x28 labeled fashion images

    Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. Zalando intends Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits.

    The original MNIST dataset contains a lot of handwritten digits. Members of the AI/ML/Data Science community love this dataset and use it as a benchmark to validate their algorithms. In fact, MNIST is often the first dataset researchers try. "If it doesn't work on MNIST, it won't work at all", they said. "Well, if it does work on MNIST, it may still fail on others."

    Zalando seeks to replace the original MNIST dataset

    Each image is 28 pixels in height and 28 pixels in width, for a total of 784 pixels in total. Each pixel has a single pixel-value associated with it, indicating the lightness or darkness of that pixel, with higher numbers meaning darker. This pixel-value is an integer between 0 and 255. The training and test data sets have 785 columns. The first column consists of the class labels (see above), and represents the article of clothing. The rest of the columns contain the pixel-values of the associated image.

    • To locate a pixel on the image, suppose that we have decomposed x as x = i * 28 + j, where i and j are integers between 0 and 27. The pixel is located on row i and column j of a 28 x 28 matrix.

    • For example, pixel31 indicates the pixel that is in the fourth column from the left, and the second row from the top, as in the ascii-diagram below.

    Labels

    Each training and test example is assigned to one of the following labels:

    • 0 T-shirt/top

    • 1 Trouser

    • 2 Pullover

    • 3 Dress

    • 4 Coat

    • 5 Sandal

    • 6 Shirt

    • 7 Sneaker

    • 8 Bag

    • 9 Ankle boot

    译:

    Fashion MNIST

    一个由70000张28x28标签的时尚图片组成的类似MNIST的数据集

    Fashion MNIST是Zalando文章图像的数据集,包含60000个示例的训练集和10000个示例的测试集。每个示例都是一个28x28灰度图像,与10个类中的一个标签相关联。Zalando打算让Fashion MNIST直接替代原来的MNIST数据集,用于机器学习算法的基准测试。它共享相同的图像大小和结构的训练和测试分割。

    原始MNIST数据集包含大量手写数字。AI/ML/Data-Science社区的成员喜欢这个数据集,并将其作为验证算法的基准。事实上,MNIST往往是研究人员尝试的第一个数据集。”“如果它在MNIST上不起作用,它就根本不起作用了,”他们说好吧,如果它对MNIST有效,那么其他人也可能失败。”

    Zalando试图替换原始的MNIST数据集

    每个图像的高度为28像素,宽度为28像素,总共784个像素。每个像素都有一个与之相关联的像素值,表示该像素的亮度或暗度,数字越大表示越暗。此像素值是介于0和255之间的整数。训练和测试数据集有785列。第一列由类标签(见上文)组成,代表服装。其余列包含关联图像的像素值。

    ●为了在图像上定位一个像素,假设我们将x分解为x=i*28+j,其中i和j是0到27之间的整数。像素位于28 x 28矩阵的第i行和第j列。

    ●例如,pixel31表示左起第四列和上第二行的像素,如下面的ascii图所示。

    标签

    每个培训和测试示例都分配给以下标签之一:

    ●0件T恤/上衣

    ●1条裤子

    ●2件套头衫

    ●3件连衣裙

    ●4层

    ●5双凉鞋

    ●6件衬衫

    ●7双运动鞋

    ●8袋

    ●9踝靴

    大家可以到官网地址下载数据集,我自己也在百度网盘分享了一份。可关注本人公众号,回复“2020102701”获取下载链接。

     

    展开全文
  • fashion mnist

    2020-10-08 16:31:47
    数据集下载 数据集读取
    展开全文
  • 今天我们要训练的模型是基于Keras框架,来训练FashionMNIST图像识别模型,该模型和MNIST是一样的分类数量。MNIST的分类是0到9的十个数字FashionMNIST的分类是这十个分类:'t_shirt', 'trouser', 'pullover', 'dress'...

    2ec175d00699895a7165fc0eadcb2f47.png

    今天我们要训练的模型是基于Keras框架,来训练FashionMNIST图像识别模型,该模型和MNIST是一样的分类数量。

    • MNIST的分类是0到9的十个数字
    • FashionMNIST的分类是这十个分类:'t_shirt', 'trouser', 'pullover', 'dress', 'coat', 'sandal', 'shirt', 'sneaker', 'bag', 'ankle_boots'

    平时我们在训练AI模型时,都是在CPU或者GPU服务器上,今天在此示例中,我们尝试使用tf.keras在Google Cloud TPU上训练基于FashionMNIST数据集的模型。该模型在Cloud TPU上训练1个Epoch,大约需要2分钟运行完毕。

    学习目标
    在本Jupyter Notebook中,我们将学习:

    • 构建标准的卷积网络,在Keras的每一层之间有3层,具有Dropout和批量标准化操作。
    • 使用yield来创建数据集的生成器和fit_generator来训练模型。
    • 运行模型预测以查看模型如何预测fashion类别并输出结果。

    TPU位于Google Cloud中,为获得最佳性能,可以直接从Google云端存储(GCS)读取数据,让我们一起看看代码是如何编写的。

    获取数据
    首先使用tf.keras.datasets下载Fashion MNIST数据集,如下所示:

    import 

    定义模型

    以下示例使用标准conv-net,每层都有Dropout和批量标准化:

    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.BatchNormalization(input_shape=x_train.shape[1:]))
    model.add(tf.keras.layers.Conv2D(64, (5, 5), padding='same', activation='elu'))
    model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
    model.add(tf.keras.layers.Dropout(0.25))
    
    model.add(tf.keras.layers.BatchNormalization(input_shape=x_train.shape[1:]))
    model.add(tf.keras.layers.Conv2D(128, (5, 5), padding='same', activation='elu'))
    model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
    model.add(tf.keras.layers.Dropout(0.25))
    
    model.add(tf.keras.layers.BatchNormalization(input_shape=x_train.shape[1:]))
    model.add(tf.keras.layers.Conv2D(256, (5, 5), padding='same', activation='elu'))
    model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=(2,2)))
    model.add(tf.keras.layers.Dropout(0.25))
    
    model.add(tf.keras.layers.Flatten())
    model.add(tf.keras.layers.Dense(256))
    model.add(tf.keras.layers.Activation('elu'))
    model.add(tf.keras.layers.Dropout(0.5))
    model.add(tf.keras.layers.Dense(10))
    model.add(tf.keras.layers.Activation('softmax'))
    model.summary()

    输出的模型概要如下:

    Layer (type)                 Output Shape              Param #   
    =================================================================
    batch_normalization_v1 (Batc (None, 28, 28, 1)         4         
    _________________________________________________________________
    conv2d (Conv2D)              (None, 28, 28, 64)        1664      
    _________________________________________________________________
    max_pooling2d (MaxPooling2D) (None, 14, 14, 64)        0         
    _________________________________________________________________
    dropout (Dropout)            (None, 14, 14, 64)        0         
    _________________________________________________________________
    batch_normalization_v1_1 (Ba (None, 14, 14, 64)        256       
    _________________________________________________________________
    conv2d_1 (Conv2D)            (None, 14, 14, 128)       204928    
    _________________________________________________________________
    max_pooling2d_1 (MaxPooling2 (None, 7, 7, 128)         0         
    _________________________________________________________________
    dropout_1 (Dropout)          (None, 7, 7, 128)         0         
    _________________________________________________________________
    batch_normalization_v1_2 (Ba (None, 7, 7, 128)         512       
    _________________________________________________________________
    conv2d_2 (Conv2D)            (None, 7, 7, 256)         819456    
    _________________________________________________________________
    max_pooling2d_2 (MaxPooling2 (None, 3, 3, 256)         0         
    _________________________________________________________________
    dropout_2 (Dropout)          (None, 3, 3, 256)         0         
    _________________________________________________________________
    flatten (Flatten)            (None, 2304)              0         
    _________________________________________________________________
    dense (Dense)                (None, 256)               590080    
    _________________________________________________________________
    activation (Activation)      (None, 256)               0         
    _________________________________________________________________
    dropout_3 (Dropout)          (None, 256)               0         
    _________________________________________________________________
    dense_1 (Dense)              (None, 10)                2570      
    _________________________________________________________________
    activation_1 (Activation)    (None, 10)                0         
    =================================================================
    Total params: 1,619,470
    Trainable params: 1,619,084
    Non-trainable params: 386
    _________________________________________________________________

    在TPU上训练
    要开始训练,请在TPU上构建模型,然后进行编译。

    以下代码演示了如何使用生成器函数和fit_generator来训练模型。 或者,您可以将x_train和y_train传递给tpu_model.fit(),代码如下:

    import os
    tpu_model = tf.contrib.tpu.keras_to_tpu_model(
        model,
        strategy=tf.contrib.tpu.TPUDistributionStrategy(
            tf.contrib.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
        )
    )
    tpu_model.compile(
        optimizer=tf.train.AdamOptimizer(learning_rate=1e-3, ),
        loss=tf.keras.losses.sparse_categorical_crossentropy,
        metrics=['sparse_categorical_accuracy']
    )
    
    def train_gen(batch_size):
      while True:
        offset = np.random.randint(0, x_train.shape[0] - batch_size)
        yield x_train[offset:offset+batch_size], y_train[offset:offset + batch_size]
        
    
    tpu_model.fit_generator(
        train_gen(1024),
        epochs=1,
        steps_per_epoch=1000,
        validation_data=(x_test, y_test),
    )

    测试结果(Inference)

    现在您已经完成了训练,看看模型如何预测fashion类别,如下代码:

    LABEL_NAMES = ['t_shirt', 'trouser', 'pullover', 'dress', 'coat', 'sandal', 'shirt', 'sneaker', 'bag', 'ankle_boots']
    
    cpu_model = tpu_model.sync_to_cpu()
    
    from matplotlib import pyplot
    %matplotlib inline
    
    def plot_predictions(images, predictions):
      n = images.shape[0]
      nc = int(np.ceil(n / 4))
      f, axes = pyplot.subplots(nc, 4)
      for i in range(nc * 4):
        y = i // 4
        x = i % 4
        axes[x, y].axis('off')
        
        label = LABEL_NAMES[np.argmax(predictions[i])]
        confidence = np.max(predictions[i])
        if i > n:
          continue
        axes[x, y].imshow(images[i])
        axes[x, y].text(0.5, 0.5, label + 'n%.3f' % confidence, fontsize=14)
    
      pyplot.gcf().set_size_inches(8, 8)  
    
    plot_predictions(np.squeeze(x_test[:16]), 
                     tpu_model.predict(x_test[:16]))

    输出的预测效果如图所示:

    2175889daef30ae10c0deb6672d2f410.png

    课外阅读

    在Google云端平台上,除了预先配置的深度学习虚拟机上提供的GPU和TPU之外,还可以找到用于训练自定义模型的AutoML(测试版),无需编写代码在Cloud ML Engine上,就可以运行并行训练模型,超参数调整,以及强大的分布式硬件上的自定义模型。

    代码已经上传到了Github:

    VictorZhang2014/paddle_vs_tensorflow_vs_kerasgithub.com
    06dfed87ad926395352fed872df92cc6.png

    学习人工智能、Python、机器学习、深度学习

    立即长按二维码,选择关注公众号,从此踏上人工智能的世界

    2229b077df94406b68fc6f0bcd5bc695.png
    展开全文
  • 数据集包括了MNIST和FashionMNIST,有原始数据集raw和经过torchvision.datasets处理过的processed目录
  • fashion mnist代码

    2019-03-07 10:42:12
    fashion mnist训练代码,注意tensorflow的版本问题。必须要在1.4.0以上
  • 最近在撸pytorch框架,这里参考深度学习经典数据集mnist的“升级版”fashion mnist,来做图像分类,主要目的是熟悉pytorch框架,代码中包含了大量的pytorch使用相关的注释。1. 数据集介绍(1)MNISTMNIST是深度学习...

    最近在撸pytorch框架,这里参考深度学习经典数据集mnist的“升级版”fashion mnist,来做图像分类,主要目的是熟悉pytorch框架,代码中包含了大量的pytorch使用相关的注释。

    1. 数据集介绍

    (1)MNIST

    MNIST是深度学习最基本的数据集之一,由CNN鼻祖yann lecun建立的一个手写字符数据集,包含60000张训练图像和10000张测试图像,包含数字0-9共10个类别.

    912bfef2cfa85ca439d5a41f52c50f1f.png

    (2)FASHION MNIST

    由于MNIST数据集太简单,简单的网络就可以达到99.7%的top one准确率,也就是说在这个数据集上表现较好的网络,在别的任务上表现不一定好。因此zalando research的工作人员建立了fashion mnist数据集,该数据集由衣服、鞋子等服饰组成,包含70000张图像,其中60000张训练图像加10000张测试图像,图像大小为28x28,单通道,共分10个类,如下图,每3行表示一个类。

    39e4306658b997a3c0b2a43cc892801a.png

    数据集信息如下:

    dcdceb1bbb0b7b73df31a01f5c2d3482.png

    数据集共分10个类,类别描述如下:

    f30b1b4dbf92919048c49b6819343b6b.png

    2. pytorch进行分类

    pytorch中提供了这个数据集的下载接口,下面分别使用全连接网络和CNN网络来进行分类

    (1)FC网络

    输入图像大小为28x28,设计如下全连接网络,代码命名为02_fashion_mnist_fc.py

    FC1(784) + Relu(1000) + FC2(500) + Relu + FC3(200) + Relu3 + FC4(10) + log_softmax

    from __future__ import print_function   # 从future版本导入print函数功能
    import argparse                         # 加载处理命令行参数的库
    import torch                            # 引入相关的包
    import torch.nn as nn                   # 指定torch.nn别名nn
    import torch.nn.functional as F         # 引用神经网络常用函数包,不具有可学习的参数
    import torch.optim as optim
    from torchvision import datasets, transforms  # 加载pytorch官方提供的dataset
    
    class Net(nn.Module):
        def __init__(self):
            super(Net, self).__init__()
            self.fc1 = nn.Linear(784, 1000) # 784表示输入神经元数量,1000表示输出神经元数量
            self.fc2 = nn.Linear(1000, 500)
            self.fc3 = nn.Linear(500, 200)
            self.fc4 = nn.Linear(200, 10)
    
        def forward(self, x):
            x = x.view(-1, 28*28)
            x = F.relu(self.fc1(x))
            x = F.relu(self.fc2(x))
            x = F.relu(self.fc3(x))
            x = self.fc4(x)
            return F.log_softmax(x, dim=1)  #Applies a softmax followed by a logarithm, output batch * classes tensor
    
    def train(args, model, device, train_loader, optimizer, epoch):
        model.train()
        for batch_idx, (data, target) in enumerate(train_loader):
            data, target = data.to(device), target.to(device)
            optimizer.zero_grad()
            output = model(data)
            loss = F.nll_loss(output, target)       # negative log likelihood loss(nll_loss), sum up batch cross entropy
            loss.backward()
            optimizer.step()                        # 根据parameter的梯度更新parameter的值
            #print(epoch, batch_idx, type(batch_idx))
            if batch_idx % args.log_interval == 0:
                print('Train Epoch: {} [{}/{} ({:.0f}%)]tLoss: {:.6f}'.format(
                    epoch, batch_idx * len(data), len(train_loader.dataset),
                           100. * batch_idx / len(train_loader), loss.item()))
    
    
    def test(args, model, device, test_loader):
        model.eval()
        test_loss = 0
        correct = 0
        with torch.no_grad():       #无需计算梯度
            for data, target in test_loader:
                data, target = data.to(device), target.to(device)
                output = model(data)
                test_loss += F.nll_loss(output, target, reduction='sum').item()  # sum up batch loss
                pred = output.argmax(dim=1, keepdim=True)  # get the index of the max log-probability
                correct += pred.eq(target.view_as(pred)).sum().item()
    
        test_loss /= len(test_loader.dataset)
    
        print('nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)n'.format(
            test_loss, correct, len(test_loader.dataset),
            100. * correct / len(test_loader.dataset)))
    
    
    def main():
        # Training settings
        parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
        parser.add_argument('--batch-size', type=int, default=64, metavar='N',
                            help='input batch size for training (default: 64)')
        parser.add_argument('--test-batch-size', type=int, default=1000, metavar='N',
                            help='input batch size for testing (default: 1000)')
        parser.add_argument('--epochs', type=int, default=10, metavar='N',
                            help='number of epochs to train (default: 10)')
        parser.add_argument('--lr', type=float, default=0.01, metavar='LR',
                            help='learning rate (default: 0.01)')
        parser.add_argument('--momentum', type=float, default=0.5, metavar='M',
                            help='SGD momentum (default: 0.5)')
        parser.add_argument('--no-cuda', action='store_true', default=False,
                            help='disables CUDA training')
        parser.add_argument('--seed', type=int, default=1, metavar='S',
                            help='random seed (default: 1)')
        parser.add_argument('--log-interval', type=int, default=10, metavar='N',
                            help='how many batches to wait before logging training status')
    
        parser.add_argument('--save-model', action='store_true', default=True,
                            help='For Saving the current Model')
        args = parser.parse_args()
        use_cuda = not args.no_cuda and torch.cuda.is_available()
    
        torch.manual_seed(args.seed)
    
        device = torch.device("cuda" if use_cuda else "cpu")
    
        kwargs = {'num_workers': 1, 'pin_memory': True} if use_cuda else {}
        train_loader = torch.utils.data.DataLoader(
            datasets.FashionMNIST('./fashionmnist_data/', train=True, download=True,
                           transform=transforms.Compose([
                               transforms.ToTensor(),
                               transforms.Normalize((0.1307,), (0.3081,))
                           ])),
            batch_size=args.batch_size, shuffle=True, **kwargs)
        test_loader = torch.utils.data.DataLoader(
            datasets.FashionMNIST('./fashionmnist_data/', train=False, transform=transforms.Compose([
                transforms.ToTensor(),
                transforms.Normalize((0.1307,), (0.3081,))
            ])),
            batch_size=args.test_batch_size, shuffle=True, **kwargs)
    
        model = Net().to(device)
        optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum)   #optimizer存储了所有parameters的引用,每个parameter都包含gradient
        scheduler = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[12, 24], gamma=0.1)   #学习率按区间更新
    
        for epoch in range(1, args.epochs + 1):
            train(args, model, device, train_loader, optimizer, epoch)
            test(args, model, device, test_loader)
    
        if (args.save_model):
            torch.save(model.state_dict(), "mnist_fc.pt")
    
    # 当.py文件直接运行时,该语句及以下的代码被执行,当.py被调用时,该语句及以下的代码不被执行
    if __name__ == '__main__':
        main()

    python 02_fashion_mnist_fc.py --epochs=36

    7b94bb1b74105ca5c5f761c1bd1a4423.png

    备注:

    • 数据集下载比较慢,第一次训练时,train_loader中download设置为True,后面再训练时改为False
    • F.log_softmax只是对输出结果做softmax后再取log
    • optimizer存储了所有parameters的引用,每个parameter都包含gradient
    • scheduler根据设置的epoch区间来调整学习率大小,调整率为gamma

    训练过程中,随机选择1个batch的数据显示,如下:

    8ffe932fd4692bcb775006d6d6d2c95b.png

    训练结果如下,top1准确率为88%,网络参数大小为5.1M

    3f8f3b2bc486dd7e441b8d363e104e19.png

    2.2 CNN网络

    FC网络参数量太大,而CNN网络考虑到图像的局部关联特性,使用卷积网络,参数量大小减小,设计如下CNN,代码全名为02_fashion_mnist_cnn.py

    conv(1, 20, 5) + Relu + conv(20, 50, 5) + flatten + Relu + FC(10) + log_softmax

    from __future__ import print_function   # 从future版本导入print函数功能
    import argparse                         # 加载处理命令行参数的库
    import torch                            # 引入相关的包
    import torch.nn as nn                   # 指定torch.nn别名nn
    import torch.nn.functional as F         # 引用神经网络常用函数包,不具有可学习的参数
    import torch.optim as optim
    from torchvision import datasets, transforms  # 加载pytorch官方提供的dataset
    
    class Net(nn.Module):
        def __init__(self):
            super(Net, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5, 1)  # 1表示输入通道,20表示输出通道,5表示conv核大小,1表示conv步长
            self.conv2 = nn.Conv2d(20, 50, 5, 1)
            self.fc1 = nn.Linear(4 * 4 * 50, 500)
            self.fc2 = nn.Linear(500, 10)
    
        def forward(self, x):
            x = F.relu(self.conv1(x))
            x = F.max_pool2d(x, 2, 2)
            x = F.relu(self.conv2(x))
            x = F.max_pool2d(x, 2, 2)
            x = x.view(-1, 4 * 4 * 50)
            x = F.relu(self.fc1(x))
            x = self.fc2(x)
            return F.log_softmax(x, dim=1)
    
    
    def train(args, model, device, train_loader, optimizer, epoch):
        model.train()
        for batch_idx, (data, target) in enumerate(train_loader):
            data, target = data.to(device), target.to(device)
            optimizer.zero_grad()
            output = model(data)
            loss = F.nll_loss(output, target)
            loss.backward()
            optimizer.step()
            if batch_idx % args.log_interval == 0:
                print('Train Epoch: {} [{}/{} ({:.0f}%)]tLoss: {:.6f}'.format(
                    epoch, batch_idx * len(data), len(train_loader.dataset),
                           100. * batch_idx / len(train_loader), loss.item()))
    
    
    def test(args, model, device, test_loader):
        model.eval()
        test_loss = 0
        correct = 0
        with torch.no_grad():
            for data, target in test_loader:
                data, target = data.to(device), target.to(device)
                output = model(data)
                test_loss += F.nll_loss(output, target, reduction='sum').item()  # sum up batch loss
                pred = output.argmax(dim=1, keepdim=True)  # get the index of the max log-probability
                correct += pred.eq(target.view_as(pred)).sum().item()
    
        test_loss /= len(test_loader.dataset)
    
        print('nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)n'.format(
            test_loss, correct, len(test_loader.dataset),
            100. * correct / len(test_loader.dataset)))
    
    
    def main():
        # Training settings
        parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
        parser.add_argument('--batch-size', type=int, default=64, metavar='N',
                            help='input batch size for training (default: 64)')
        parser.add_argument('--test-batch-size', type=int, default=1000, metavar='N',
                            help='input batch size for testing (default: 1000)')
        parser.add_argument('--epochs', type=int, default=10, metavar='N',
                            help='number of epochs to train (default: 10)')
        parser.add_argument('--lr', type=float, default=0.01, metavar='LR',
                            help='learning rate (default: 0.01)')
        parser.add_argument('--momentum', type=float, default=0.5, metavar='M',
                            help='SGD momentum (default: 0.5)')
        parser.add_argument('--no-cuda', action='store_true', default=False,
                            help='disables CUDA training')
        parser.add_argument('--seed', type=int, default=1, metavar='S',
                            help='random seed (default: 1)')
        parser.add_argument('--log-interval', type=int, default=10, metavar='N',
                            help='how many batches to wait before logging training status')
    
        parser.add_argument('--save-model', action='store_true', default=False,
                            help='For Saving the current Model')
        args = parser.parse_args()
        use_cuda = not args.no_cuda and torch.cuda.is_available()
    
        torch.manual_seed(args.seed)
    
        device = torch.device("cuda" if use_cuda else "cpu")
    
        kwargs = {'num_workers': 1, 'pin_memory': True} if use_cuda else {}
        train_loader = torch.utils.data.DataLoader(
            datasets.FashionMNIST('./fashionmnist_data/', train=True, download=False,
                           transform=transforms.Compose([
                               transforms.ToTensor(),
                               transforms.Normalize((0.1307,), (0.3081,))
                           ])),
            batch_size=args.batch_size, shuffle=True, **kwargs)
        test_loader = torch.utils.data.DataLoader(
            datasets.FashionMNIST('./fashionmnist_data/', train=False, transform=transforms.Compose([
                transforms.ToTensor(),
                transforms.Normalize((0.1307,), (0.3081,))
            ])),
            batch_size=args.test_batch_size, shuffle=True, **kwargs)
    
        model = Net().to(device)
        optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum)
        scheduler = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[12, 24], gamma=0.1)
    
        for epoch in range(1, args.epochs + 1):
            train(args, model, device, train_loader, optimizer, epoch)
            test(args, model, device, test_loader)
    
        if (args.save_model):
            torch.save(model.state_dict(), "mnist_cnn.pt")
    
    
    # 当.py文件直接运行时,该语句及以下的代码被执行,当.py被调用时,该语句及以下的代码不被执行
    if __name__ == '__main__':
        main()

    python 02_fashion_mnist_cnn.py --epochs=36

    c5f21c4c3c6eb454e3dd7f2ae47a4354.png

    训练结果如下,top1准确率为91%。

    c22c9f4b7a08ee5429f817efdfd1a316.png

    3. references

    [1] https://github.com/zalandoresearch/fashion-mnist

    [2] https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html

    [3] https://github.com/zalandoresearch/fashion-mnist

    展开全文
  • 概观在此示例中,您可以尝试使用tf.keras和Cloud TPU在FashionMNIST数据集上训练模型。该模型在Cloud TPU上训练10个Epoch,大约需要2分钟才能运行。学习目标在本文中,您将学习如何:标准conv net的代码,在Keras的...
  • title: "Tensorflow2.0学习笔记-fashion mnist数据的分类示例" categories: Tensorflow description: "从tensoflow官网学习tensorflow2.0。"keywords: 学习笔记, tensorflow源代码地址:...
  • FashionMNIST.zip

    2020-10-24 18:12:26
    FashionMNIST数据集下载。不同于MNIST手写数据集,Fashion-MNIST数据集包含了10个类别的图像,分别是:t-shirt(T恤),trouser(牛仔裤),pullover(套衫),dress(裙子),coat(外套),sandal(凉鞋),shirt...
  • FashionMNIST.7z

    2021-01-06 14:04:21
    FashionMNIST数据集 已转换为pytorch要求的.pt格式
  • mnistfashion mnist区别

    2020-06-21 20:54:03
    mnist之后,还出现了一个旨在代替经典mnist数据集的Fashion MNIST,同mnist一样,它也是被用作深度学习程序的“hello world”,而且也是由70k张28*28的图片组成的,它们也被分为10类,有60k被用作训练,10k被用作...
  • FashionMNIST的jpg格式数据
  • MNISTFASHION MNIST 数据读取

    万次阅读 2018-05-05 11:33:19
    概要 代码 结果展示概要mnist 数据集链接:http://yann.lecun.com/exdb/mnist/ fashion_mnist:...所以现在准备采用fashion_mnist。 两者的读取方式完全一致。这里以fashion mnist作为例子。Fa
  • FashionMNIST数据集.zip

    2020-02-20 18:03:21
    用于动手学深度学习-pytorch的FashionMNIST数据集,如果你的github下载速度很慢的话,可以下载这个数据集,就比较方便
  • Fashion MNIST数据集介绍及下载

    千次阅读 2020-01-06 21:32:52
    Fashion MNIST(服饰数据集)的作用是经典MNIST数据集的简易替换,MNIST数据集包含手写数字(阿拉伯数字)的图像,两者图像格式及大小都相同。Fashion MNIST比常规 MNIST手写数据将更具挑战性。两者数据集都较小,...
  • tensorflow——FashionMnist

    2019-07-24 17:14:45
    数据集下载 ... 和mnist数据集类似。 数据集读取问题请详看tensorflow——FashionMnist数据集读取问题 数据表现形式用matlibplot 与mnist数据不同的是,此次数据集是非单一热点模式 奉上代...
  • torchvision.datasets.FashionMNIST(root='~/Datasets/FashionMNIST', train=True, download=True, transform=transforms.ToTensor()) mnist_test = torchvision.datasets.FashionMNIST(root='~/Datasets/Fashion...
  • Added Fashion MNIST jupyter notebook <p>Check list: * [ ] New tests are added (if a new feature is added) * [ ] New doc strings: description and/or example code are in RST format * [ ] Documentation ...
  • 基于keras的 Fashion MNIST分类 import keras import numpy as np import matplotlib.pyplot as plt fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels)...
  • 开源数据集Fashion Mnist的PNG格式图片的压缩包,包含了60000张训练图片和10000张测试图片。
  • 最近在撸pytorch框架,这里参考深度学习经典数据集mnist的“升级版”fashion mnist,来做图像分类,主要目的是熟悉pytorch框架,代码中包含了大量的pytorch使用相关的注释。1. 数据集介绍(1)MNISTMNIST是深度学习最...
  • Fashion Mnist中的softmax应用 1、Fashion Mnist数据集 链接:https://pan.baidu.com/s/1jPYlBMg-MTQ7nxnLMwjsLQ 提取码:3zdy 共70000张图片 2、导入相关的包 import tensorflow as tf import pandas as pd #data=...
  • 加载并可视化FashionMNIST在这个notebook中,我们要加载并查看Fashion-MNIST 数据库中的图像。任何分类问题的第一步,都是查看你正在使用的数据集。这样你可以了解有关图像和标签格式的一些详细信息,以及对如何定义...
  • tensorflow2.0 CNN fashion MNIST图像分类

    千次阅读 2020-11-09 18:28:52
    fashion MNIST图像分类 数据集简介   在 2017年8月份,德国研究机构Zalando Research在GitHub上推出了一个全新的数据集——fashion MNIST数据集,其中训练集包含60000个样例,测试集包含 10000个样例,分为10类,...
  • fashionMNIST results

    2020-12-09 06:04:24
    <div><p>This code is linked from the <a href="https://github.com/zalandoresearch/fashion-mnist">fashion-mnist</a> repo, w/ very good results. Do you have a script somewhere I might be able to use to ...
  • Fashion MNIST 数据集

    2020-12-03 08:33:35
    Fashion-MNIST是Zalando(一家德国的时尚科技公司)提供的商品数据集,数据为10种类别,并且包括了6W的训练集和1W的测试集。
  • Fashion MNIST数据集是德国研究机构Zalando Research于2017年8月份,在Github上推出的一个经典数据集。 其中训练集包含60000个样例,测试集包含10000个样例,分为10类,每一类的样本训练样本数量和测试样本数量相同...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,159
精华内容 863
关键字:

fashionmnist