mnist

PyTorch 之 Datasets

China☆狼群 提交于 2019-11-28 22:07:50
实现一个定制的 Dataset 类 Datasets 的框架: class CustomDataset(data.Dataset): # 需要继承 data.Dataset def __init__(self): # TODO # Initialize file path or list of file names. pass def __getitem__(self, index): # TODO # 1. 从文件中读取指定 index 的数据(例:使用 numpy.fromfile, PIL.Image.open) # 2. 预处理读取的数据(例:torchvision.Transform) # 3. 返回数据对(例:图像和对应标签) pass def __len__(self): # TODO # You should change 0 to the total size of your dataset. return 0 下面是官方 MNIST 的例子: class MNIST(data.Dataset): """`MNIST <http://yann.lecun.com/exdb/mnist/>`_ Dataset. Args: root (string): Root directory of dataset where ``processed/training.pt``

tensorflow mnist新手文档

只愿长相守 提交于 2019-11-28 21:16:53
官方文档 https://www.tensorflow.org/versions/r1.1/get_started/mnist/beginners minist数据库 每一张图片对应28x28大小的灰度图,也就是大小为784,55,000张训练数据[55000, 784],10,000测试数据,每个数据对应一个label标签(0到9) 但是label用的是one-hot vectors(独热编码)格式[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],那么训练数据的标签库就是[55000, 10]数据为浮点。 tensorflow.placeholder(dtype, shape=None, name=None), dtype:数据类型。常用的是tf.float32,tf.float64等数值类型 shape:数据形状。默认是None,就是一维值,也可以是多维,比如[2,3], [None, 3]表示列是3,行不定 name:名称 import tensorflow as tf 读mnist数据 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) x = tf

Tensorflow Deep MNIST: Resource exhausted: OOM when allocating tensor with shape[10000,32,28,28]

♀尐吖头ヾ 提交于 2019-11-28 18:24:54
This is the sample MNIST code I am running: from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('MNIST_data', one_hot=True) import tensorflow as tf sess = tf.InteractiveSession() x = tf.placeholder(tf.float32, shape=[None, 784]) y_ = tf.placeholder(tf.float32, shape=[None, 10]) W = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) y = tf.nn.softmax(tf.matmul(x,W) + b) def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(initial) def bias_variable(shape): initial = tf.constant(0.1, shape=shape)

tensorflow之tensorboard

吃可爱长大的小学妹 提交于 2019-11-28 16:21:22
参考 https://www.cnblogs.com/felixwang2/p/9184344.html 边学习,边练习 1 # https://www.cnblogs.com/felixwang2/p/9184344.html 2 # TensorFlow(七):tensorboard网络执行 3 # MNIST数据集 手写数字 4 import tensorflow as tf 5 from tensorflow.examples.tutorials.mnist import input_data 6 7 # 参数概要 8 def variable_summaries(var): 9 with tf.name_scope('summaries'): 10 mean=tf.reduce_mean(var) 11 tf.summary.scalar('mean',mean)# 平均值 12 with tf.name_scope('stddev'): 13 stddev=tf.sqrt(tf.reduce_mean(tf.square(var-mean))) 14 tf.summary.scalar('stddev',stddev)# 标准差 15 tf.summary.scalar('max',tf.reduce_max(var)) # 最大值 16 tf.summary

How to load MNIST via TensorFlow (including download)?

不打扰是莪最后的温柔 提交于 2019-11-28 12:01:52
问题 The TensorFlow documentation for MNIST recommends multiple different ways to load the MNIST dataset: https://www.tensorflow.org/tutorials/layers https://www.tensorflow.org/versions/r1.2/get_started/mnist/beginners https://www.tensorflow.org/versions/r1.2/get_started/mnist/pros All ways described in the documentation throw many deprecated warnings with TensorFlow 1.8. The way I'm currently loading MNIST and creating batches for training: class MNIST: def __init__(self, optimizer): ... self

Reading MNIST Image Database binary file in MATLAB

老子叫甜甜 提交于 2019-11-28 11:35:13
I have a binary file from the MNIST image database, renamed as "myfile.dat". This consists of a set of 4 unsigned 32-bit integers, followed by a chain of unsigned 8-bit integers. I want to read this file and store its contents as an array. Here is my code: file_id = fopen('myfile.dat', 'rb'); data = fread(file_id, 'int'); size(data) class(data) And the output is: ans = 2502 1 ans = double The size of (2502, 1) is as expected. But why is it telling me that the data is double , when I have specified it to be int ? I know what the first few numbers should be and the output data is not as expected

Keras学习(一)MNIST 识别---DNN 实现

可紊 提交于 2019-11-28 10:38:49
【本系列博文是学习 Keras 的笔记,Keras 版本为2.1.5,主要的参考资料为: Keras中文文档 】 我们直接从一个简单的 DNN MNIST 的例子开始学习,程序代码来自于 Keras 的 examples 中的 mnist_mlp.py 这个例子非常简单,我们只实现一个具有 Dropout 层的 DNN。 网络的建立和训练 首先载入模块相关的模块:Sequential,用以生成我们的 model, 我们只要向这个 model 中 add 不同的层就可以构建我们的网络;Dense,全连接层;Dropout,Dropout 层;optimizers是优化器。 import keras from keras.models import Sequential from keras.layers import Dense, Dropout from keras.optimizers import RMSprop import numpy as np 现在准备载入数据,如果第一次运行需下载 MNIST 数据: from keras.datasets import mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() mnist.load_data会将数据缓存起来,为了多次使用定义如下函数: def load

MNIST数据集转为.jpg图片格式

六月ゝ 毕业季﹏ 提交于 2019-11-28 06:40:10
从mnist官网下载下来的mnist手写数据集是二进制文件流格式的,不能直接查看,如果需要查看,需要将二进制文件转化为jpg格式,可以用各种编程语言实现,如MATLAB、Python、C++等,本文是使用C++在Ubuntu 16.04操作系统下实现的,过程中出现许多问题,现记录如下: 1、问题描述 编译时出现一下错误 no matching function for call to std: :basic_ifstream<char> : : ( std: :string& ) 原因:根据提示可以看出是读取文件ifstream时出现了问题,查找资料后知道是由于不同版本c++表达不同导致的,所以用g++编译器编译时要显式制定使用那个版本c++,本程序使用c++11,编译指令如下: g++ -o b .out - std =c++ 11 mnist_bin2jpg2 .cpp 2、问题: 编译时出现: 对‘ cv: :Mat : :copySize ( cv: :Mat const&)’未定义的引用 原因:编译的时候没有链接到库文件,这样导致函数没有定义,所以变异的时候要手动链接到库文件 g + + - o b . out - std=c + + 11 mnist_bin2jpg2 . cpp `pkg - config opencv - - cflags - - libs` 3

tensorflow框架学习 (七)—— tensorboard可视化工具

人走茶凉 提交于 2019-11-28 03:37:54
官方介绍: https://tensorflow.google.cn/guide/summaries_and_tensorboard 一、关于tensorboard的问题   通过pip安装tensorflow的时候会自动安装tensorboard,如果后续出现版本不对的情况,需要根据安装的tensorflow的版本来安装对应的tensorboard。   TensorBoard 通过读取 TensorFlow 的事件文件来运行,事件文件可以通过tf.summary.FileWrite类来创建,TensorFlow 的事件文件包含运行 TensorFlow 时生成的总结数据,总结数据可以用tf.summary模块中的方法来创建。   在事件文件创建好之后,要在终端模式中启动tensorbaord,例如windows系统中在cmd中用命令:tensorboard --logdir=path ,其中path为事件文件所在的目录的地址,具体如下图:      然后通过返回的网址http://DESKTOP-4K4SA9I:6006,在浏览器中输入对应的网址即可,建议用google浏览器,最后退出可视化的时候需要关闭终端的tensorboard运行。   来看一下tf.summary.FileWriter的构造函数: tf.summary.FileWriter.__init__(self

MNIST 数据集介绍

夙愿已清 提交于 2019-11-28 03:27:35
在学习机器学习的时候,首要的任务的就是准备一份通用的 数据集 ,方便与其他的算法进行比较。 MNIST数据集是一个手写数字数据集,每一张图片都是0到9中的单个数字,比如下面几个: MNIST数据库的来源是两个数据库的混合,一个来自Census Bureau employees(SD-3),一个来自high-school students(SD-1);有训练样本60000个,测试样本10000个。训练样本和测试样本中,employee和student写的都是各占一半。60000个训练样本一共大概250个人写的。训练样本和测试样本的来源人群没有交集。MNIST数据库也保留了手写数字与身份的对应关系。 TensorFlow使用MNIST 数据集 我们可以使用Tensorflow提供的 input_data.py 脚本来加载数据集: 作者:secret_liang 链接:https://www.jianshu.com/p/29b14426a409 来源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 来源: https://www.cnblogs.com/wisir/p/11389008.html