mnist

TensorFlow2.0 学习笔记(一):TensorFlow 2.0 的安装和环境配置以及上手初体验

非 Y 不嫁゛ 提交于 2019-12-08 21:09:43
专栏——TensorFlow学习笔记 文章目录 专栏——TensorFlow学习笔记 〇、写在前面 一、TensorFlow 概述 二、TensorFlow 2.0 安装与环境配置 三、第一个程序 四、简单的手写数字识别 五、稍微复杂的手写数字识别 六、总结 推荐阅读 参考文章 〇、写在前面 关于为什么要学习 TensorFlow 2.0 这件事,简单说一下,现在还是硕士在读,在课题完成中,使用 TensorFlow 1.x 真的是问题超级多,最大的烦恼就是改动网络真的麻烦,在这个时候 TensorFlow 2.0 出现了。对于新版本的 TensorFlow 有一些期待,也有一些困惑,决定尝试一下,fighting! 一、TensorFlow 概述 人工智能和深度学习的热潮将 TensorFlow 推向了至高的地位,媒体的追捧和业界的宣传也为这一源自 Google 的开源框架增添了传奇的色彩。 Google 发布的 TensorFlow 与 Facebook 发布的 Pytorch 基本上是深度学习框架的大半江山,它们各自有着狂热的追求者和拥护者,不过在我看来: 比如现在做课题研究的大多使用 Pytorch ,而业界工作大多使用 TensorFlow ,除此之外还有百度的 PaddlePaddle ,预计都会写一写学习笔记,可以期待一下。 其实学过了很多的 TensorFlow 1

动手学PyTorch | (23) AlexNet

孤人 提交于 2019-12-08 14:46:53
在LeNet提出后的将近20年里,神经⽹络⼀度被其他机器学习⽅法超越,如支持向量机。虽然LeNet可以在早期的⼩数据集上取得好的成绩,但是在更大的真实数据集上的表现并不尽如人意。⼀⽅面,神经⽹络计算复杂。虽然20世纪90年代也有过⼀一些针对神经网络的加速硬件,但并没有像之后GPU那样⼤量普及。因此,训练⼀个多通道、多层和有大量参数的卷积神经网络在当年很难完成。另⼀方面,当年研究者还没有⼤量深⼊研究参数初始化和⾮凸优化算法等诸多领域,导致复杂的神经网络的训练通常较困难。 我们在上一节看到,神经网络可以直接基于图像的原始像素进行分类。这种称为端到端(end-to- end)的⽅法节省了很多中间步骤。然而,在很长⼀段时间里更流行的是研究者通过勤劳与智慧所设计并⽣成的⼿工特征(特征工程)。这类图像分类研究的主要流程是: 1)获取图像数据集 2)使用已有的特征提取函数生成图像的特征 3)使用机器学习模型对图像的特征分类 当时认为的机器学习部分仅限最后这一步。如果那时候跟机器学习研究者交谈,他们会认为机器学习既􏰁重要又优美。优雅的定理证明了许多分类器的性质。机器学习领域生机勃勃、严谨⽽且极其有用。然而,如果跟计算机视觉研究者交谈,则是另外⼀一幅景象。他们会告诉你图像识别⾥“不可告⼈”的现实是:计算机视觉流程中真正􏰁重要的是数据和特征。也就是说,使用较⼲净的数据集和较有效的特征甚⾄

基于PyTorch实现MNIST手写字识别

♀尐吖头ヾ 提交于 2019-12-08 14:24:25
本篇不涉及模型原理,只是分享下代码。想要了解模型原理的可以去看网上很多大牛的博客。 目前代码实现了CNN和LSTM两个网络,整个代码分为四部分: Config :项目中涉及的参数; CNN :卷积神经网络结构; LSTM :长短期记忆网络结构; TrainProcess : 模型训练及评估,参数 model 控制训练何种模型( CNN or LSTM )。 完整代码 — Talk is cheap, show me the code. # -*- coding: utf-8 -*- # @author: Awesome_Tang # @date: 2019-04-05 # @version: python3.7 import torch from torchvision import datasets, transforms import torch.nn as nn import torch.optim as optim from torch.autograd import Variable from datetime import datetime class Config: batch_size = 64 epoch = 10 alpha = 1e-3 print_per_step = 100 # 控制输出 class CNN(nn.Module): def __init__

初学者必读的八个趣味机器学习项目 ‖ 教程+数据集

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 11:21:15
抽时间做项目是最好的一种投资方式,在项目中你会享受学习、保持积极性并能获得更快的进展。没有任何理论可以代替实践,虽然教材和课程能让你掌握一些基本原理,但在尝试应用时,你会发现具体操作起来比较困难。 因此项目有助于提高应用机器学习的技巧,此外在找工作中也会给自己增添一些筹码。 以下将具体介绍这八个项目,每个项目都能在一个周末完成,如果你喜欢的话,可以对其进行相关的扩展。 本文目录 1. 机器学习的角斗士 2. 扮演“点球成金” 3. 预测股票价格 4. 教会神经网络阅读的笔迹 5. 调查安然事件 6. 从Scrath开始写机器学习算法 7. 挖掘社交情绪 8. 改善卫生保健 1.机器学习的角斗士 这个项目被称为“机器学习的角斗士”,但它不是新的。这是围绕机器学习建立实际直觉最快的一种方式。目标是将现成模型应用到不同的数据集。本项目主要有3个原因令人感叹: 首先,你会根据直觉为问题找到对应的模型。该模型是否对数据丢失具有鲁棒性、该模型适合处理种类别特征?这都可以通过挖掘教材找到答案,但如果通过实践的话能学习得更好。 其次,本项目将教会你快速设计初始模型的技能。在实际应用中,如果不简单尝试的话难以知道哪些模型表现最好。 最后,这个练习可以帮助你掌握建模的流程。例如: 导入数据 数据清洗 将数据集拆成训练/测试或交叉验证集 预处理 变换 特征工程 因为使用现成的模型

How do I load in the MNIST digits and label data in MATLAB?

浪子不回头ぞ 提交于 2019-12-07 18:44:36
问题 I am trying to run the code given in the link https://github.com/bd622/DiscretHashing Discrete Hashing is a method for dimensionality reduction that is used on approximate nearest neighbor search. I want to load in the implementation on the MNIST database that is available in http://yann.lecun.com/exdb/mnist/. I have extracted the files from their compressed gz format. PROBLEM 1 : Using the solution to read MNIST database provided in Reading MNIST Image Database binary file in MATLAB I am

TensorFlow estimator number of classes does not change

痴心易碎 提交于 2019-12-07 17:38:47
问题 I tried using tensorflow estimator for the MNIST dataset. For some reason it keep saying my n_classes is set to 1 even though it is at 10! import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/",one_hot=True) feature_columns = [tf.feature_column.numeric_column("x", shape=[784])] # Build 3 layer DNN with 10, 20, 10 units respectively. classifier = tf.estimator.DNNClassifier(feature_columns=feature

How to use neural nets to recognize handwritten digits

假如想象 提交于 2019-12-07 16:00:26
问题 I followed a tutorial for creating a simple neural network using signoidal function "Using neural nets to recognize handwritten digits", the tutorial is very simple with theory and code examples. The problem is that it does not give any examples of digits recognition using network.py. For example, I have the following number and I want to recognize it as 0 from the image below What should I do next for number recognition? To make recognition of number requires the use of other technologies

Python Numpy Error: ValueError: setting an array element with a sequence

人走茶凉 提交于 2019-12-07 15:11:14
问题 I am trying to build a dataset similar to mnist.pkl.gz provided in theano logistic_sgd.py implementation. Following is my code snippet. import numpy as np import csv from PIL import Image import gzip, cPickle import theano from theano import tensor as T def load_dir_data(csv_file=""): print(" reading: %s" %csv_file) dataset=[] labels=[] cr=csv.reader(open(csv_file,"rb")) for row in cr: print row[0], row[1] try: image=Image.open(row[0]+'.jpg').convert('LA') pixels=[f[0] for f in list(image

Tensorflow MNIST Estimator: batch size affects the graph expected input?

只谈情不闲聊 提交于 2019-12-07 02:07:33
问题 I have followed the TensorFlow MNIST Estimator tutorial and I have trained my MNIST model. It seems to work fine, but if I visualize it on Tensorboard I see something weird: the input shape that the model requires is 100 x 784. Here is a screenshot: as you can see in the right box, expected input size is 100x784. I thought I would see ?x784 there. Now, I did use 100 as a batch size in training, but in the Estimator model function I also specified that the amount of input samples size is

MNIST无监督学习-自编码器

£可爱£侵袭症+ 提交于 2019-12-06 15:09:07
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import numpy as np import matplotlib.pyplot as plt mnist=input_data.read_data_sets("mnist",one_hot=True); #设置超参数 learninig_rate=0.1; training_epochs=20; batch_size=100; display_step=1; #网络的参数 n_input=784; n_hidden_1=256; n_hidden_2=128; #自动编码器设置好以后用来测试效果的图片的数量 examples_to_show=10; X=tf.placeholder("float",[None,n_input]); weights={ "encoder_h1":tf.Variable(tf.random_normal([n_input,n_hidden_1])), "encoder_h2":tf.Variable(tf.random_normal([n_hidden_1,n_hidden_2])), "decoder_h1":tf.Variable(tf.random_normal([n