import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 data mnist = input_data.read_data_sets('MNIST_data', one_hot=True) def add_layer(inputs, in_size, out_size, activation_function=None,): # add one more
题目: 1)In the first step, apply the Convolution Neural Network method to perform the training on one single CPU and testing 2)In the second step, try the distributed training on at least two CPU/GPUs and evaluate the training time. 一.单机单卡实现mnist_CNN 1
本次分类问题使用的数据集是MNIST,每个图像的大小为\(28*28\). 编写代码的步骤如下 载入数据集,分别为训练集和测试集 让数据集可以迭代 定义模型,定义损失函数,训练模型 代码 import torch import torch.nn as nn import torchvision.transforms as transforms import torchvision.datasets as dsets from torch.autograd import Variable '''下
import torch from torch.utils.data import DataLoader from torchvision import datasets from torchvision import transforms from torch import nn, optim from torch.nn import functional as F EPOCH = 1000 BATCH_SIZE = 128 LR = 0.001 DOWNLOAD_MNIST = False
MNIST(Mixed National Institute of Standards and Technology)http://yann.lecun.com/exdb/mnist/ ,入门级计算机视觉数据集,美国中学生手写数字.训练集6万张图片,测试集1万张图片.数字经过预处理.格式化,大小调整并居中,图片尺寸固定28x28.数据集小,训练速度快,收敛效果好. MNIST数据集,NIST数据集子集.4个文件.train-label-idx1-ubyte.gz 训练集标记文件(28881字节)
一.MNIST数据集读取 one hot 独热编码独热编码是一种稀疏向量,其中:一个向量设为1,其他元素均设为0.独热编码常用于表示拥有有限个可能值的字符串或标识符优点: 1.将离散特征的取值扩展到了欧式空间,离散特征的某个取值就对应欧式空间的某个点 2.机器学习算法中,特征之间距离的计算或相似度的常用计算方法都是基于欧式空间的 3.将离散型特征使用one_hot编码,会让特征之间的距离计算更加合理 import tensorflow as tf #MNIST数据集读取 import ten