anaconda+theano+keras手写字符识别新版
标题介绍运行环境了win7
看网上好多keras识别minist 但是一般由于版本问题,无法直接用,,,这里还要特别感谢keras中文文档作者(三当家SCP)。教程整的非常好。还有就是最好你在安装anaconda 之前把原来安装过的PY卸载掉,要不然安装mingw的时候会出问题,,,安装就不详细介绍了网上有很多种----大致流程——anaconda-mingw-theano(注意环境变量,系统变量啥的)-keras。
下边附上一个可用程序哈,亲测可用。。。并附上数据,数据来源于网络,见文章底部,你就不用运行的时候在下载数据,这样很容易出错的。非GPU环境 win7 64bit
好的:其实重点是新的语法的问题。。。。。。。。。。。。。。。。。。。更新地方已标红。。。。。。。
- from __future__ import absolute_import
- from __future__ import print_function
- import numpy as np
- np.random.seed(1337) # for reproducibility
- import cPickle as pickle
- from keras.models import Sequential
- from keras.layers.core import Dense, Dropout, Activation
- from keras.optimizers import SGD, Adam, RMSprop
- from keras.utils import np_utils
- '''
- Train a simple deep NN on the MNIST dataset.
- Get to 98.30% test accuracy after 20 epochs (there is *a lot* of margin for parameter tuning).
- 2 seconds per epoch on a GRID K520 GPU.
- '''
- batch_size = 128
- nb_classes = 10
- nb_epoch = 10
- def read_data(data_file):
- 24 import gzip
- 25 f = gzip.open(data_file, "rb")
- 26 train, val, test = pickle.load(f)
- 27 f.close()
- 28 train_x = train[0]
- 29 train_y = train[1]
- 30 test_x = test[0]
- 31 test_y = test[1]
- 32 return train_x, train_y, test_x, test_y
- # the data, shuffled and split between tran and test sets
- #(X_train, y_train), (X_test, y_test) = mnist.load_data()
- train_x, train_y, test_x, test_y = read_data("C:\Users\PC\.spyder2\mnist.pkl.gz")
- X_train = train_x
- X_test = test_x
- X_train = X_train.astype("float32")
- X_test = X_test.astype("float32")
- X_train /= 255
- X_test /= 255
- print(X_train.shape[0], 'train samples')
- print(X_test.shape[0], 'test samples')
- # convert class vectors to binary class matrices
- Y_train = np_utils.to_categorical(train_y, nb_classes)
- Y_test = np_utils.to_categorical(test_y, nb_classes)
- model = Sequential()
- model.add(Dense(input_dim=784, output_dim=128))
- 53 model.add(Activation('relu'))
- 54 model.add(Dropout(0.2))
- 55 model.add(Dense(output_dim=128))
- 56 model.add(Activation('relu'))
- 57 model.add(Dropout(0.2))
- 58 model.add(Dense(output_dim=10))
- 59 model.add(Activation('softmax'))
- rms = RMSprop()
- model.compile(loss='categorical_crossentropy', optimizer=rms,metrics=['accuracy'])
- 63
- 64 model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch)
- 65 score = model.evaluate(X_test, Y_test, batch_size=batch_size)
- print('Test score:', score[0])
- print('Test accuracy:', score[1])
数据在这里:http://www.cnblogs.com/xueliangliu/archive/2013/04/03/2997437.html。。。由于没法上传有15兆,我看这个大牛有这个数据,而且还附带了安装及原理等,自己看吧。。。。。。。
anaconda+theano+keras手写字符识别新版的更多相关文章
- 李宏毅 Keras手写数字集识别(优化篇)
在之前的一章中我们讲到的keras手写数字集的识别中,所使用的loss function为‘mse’,即均方差.那我们如何才能知道所得出的结果是不是overfitting?我们通过运行结果中的trai ...
- 仅用200个样本就能得到当前最佳结果:手写字符识别新模型TextCaps
由于深度学习近期取得的进展,手写字符识别任务对一些主流语言来说已然不是什么难题了.但是对于一些训练样本较少的非主流语言来说,这仍是一个挑战性问题.为此,本文提出新模型TextCaps,它每类仅用200 ...
- 100天搞定机器学习|day39 Tensorflow Keras手写数字识别
提示:建议先看day36-38的内容 TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edge ...
- 【问题解决方案】Keras手写数字识别-ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
参考:台大李宏毅老师视频课程-Keras-Demo 在载入数据阶段报错: ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接 Google之 ...
- ubuntu 16.04+Anaconda+theano+keras安装【转】
本文转载自:https://blog.csdn.net/u013786021/article/details/78370138 安装软件部分浪费了好长时间才装好.之前一直各种问题,后来卸卸了radin ...
- 利用Tensorflow实现手写字符识别
模式识别领域应用机器学习的场景非常多,手写识别就是其中一种,最简单的数字识别是一个多类分类问题,我们借这个多类分类问题来介绍一下google最新开源的tensorflow框架,后面深度学习的内容都会基 ...
- Caffe2 手写字符识别(MNIST - Create a CNN from Scratch)[8]
本教程创建一个小的神经网络用于手写字符的识别.我们使用MNIST数据集进行训练和测试.这个数据集的训练集包含60000张来自500个人的手写字符的图像,测试集包含10000张独立于训练集的测试图像.你 ...
- Keras手写识别例子(1)----softmax
转自:https://morvanzhou.github.io/tutorials/machine-learning/keras/2-2-classifier/#测试模型 下载数据: # downlo ...
- keras手写数字识别
import kerasimport timefrom keras.utils import np_utils start = time.time()(x_train, y_train), (x_te ...
随机推荐
- 拼图游戏js
实现算法: 1. JavaScript动态生成拼图:通过生成16个div,且除最后一个div不使用背景图片以外,其他div都设置拼图图片为背景.然后通过调整background-position来实现 ...
- centos7 设置系统时间与网络同步
1.安装ntpdate工具 yum -y install ntp ntpdate 2.设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org 3.将系统时间写入硬件时间 hwclo ...
- 使用oracle导出的dmp文件(包含表结构还是表数据?)
我们都知道oracle提供了一个exp程序,可以导出dmp文件,那么dmp文件中到底包含哪些东西呢? 1:有对象的信息吗?比如对象的权限? 2:有表空间信息吗? 3:有表结构吗? 4:有表的索引和触发 ...
- oracle 所有 hint(转)
oracle 10g 有64个hints , 11g 增加到71 个, 下表中红色的代表已经过时的, 粗体的是11g 新增. Optimization Goals and Approaches (2) ...
- 深度学习中的Normalization模型
Batch Normalization(简称 BN)自从提出之后,因为效果特别好,很快被作为深度学习的标准工具应用在了各种场合.BN 大法虽然好,但是也存在一些局限和问题,诸如当 BatchSize ...
- pure框架
内容: 1.介绍与入门 2.基础使用 参考资料: pure中文文档:https://www.purecss.cn/ pure实例:https://www.purecss.cn/layouts.html ...
- UVA-10115
字符查找替换,WA了N次,一次只能替换一个,下一次find必须从第0个位置开始 import java.io.File; import java.io.FileNotFoundException; i ...
- saltstack安装配置及常用命令
1.salt安装及配置详解 https://www.cnblogs.com/lgeng/p/6567424.html centos7配置: https://www.jianshu.com/p/4c91 ...
- 【独家】完美解决appium安装app时,需要手动确认安装的问题
appium初始化driver时,如果未安装该app会先进行安装,安装时,很多安卓手机都会弹框,需要手动确认安装. 如小米的机器, 这是个头疼的问题,之前在网上找遍了,只有通过adb去点相对坐标成功了 ...
- 你该知道的 TValue
你该知道的 TValue Represents a lightweight version of the Variant type. TValue is a data structure that c ...