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 ...
随机推荐
- linux Composer 安装
Composer是一个管理PHP包依赖关系的工具.我们可以使用Composer方便地管理项目中一些第三方库和自己的库. 我们可以把Composer安装到当前目录或者特定目录甚至将它变成全局命令 *执行 ...
- Eclipse里面的Maven项目如果下载依赖的jar包的源码
Window---------Properties---------------Maven--------------勾选Download Artifact Sources和Download Arti ...
- 自己根据js的兼容封装了一个小小的js库
var gys = function () { } //oParent父节点 //获取所有的子元素 gys.prototype.getElementChildren = function (oPare ...
- ffmpeg 编码(视屏)
分析ffmpeg_3.3.2 muxing 1:分析主函数,代码如下: int main(int argc, char **argv) { OutputStream video_st = { }, a ...
- ECCV 2018 | 给Cycle-GAN加上时间约束,CMU等提出新型视频转换方法Recycle-GAN
CMU 和 Facebook 的研究者联合进行的一项研究提出了一种新型无监督视频重定向方法 Recycle-GAN,该方法结合了时间信息和空间信息,可实现跨域转换,同时保留目标域的风格.相较于只关注空 ...
- Linux--多网卡的7种Bond模式和交换机配置
网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是一种常用的技术,我们公司基本所有的项目相关服务器都做了bond,这里总结整理,以便待查. bond ...
- 模板方法模式( TemplateMethod)
定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤. AbstractClass 是抽象类,其实也是一个抽象模板,定义并实现 ...
- c# 制作自定义控件并生成dll文件旷展到其他项目使用
1.新建项目,同时添加一个类库,然后在类库里面定义自己的控件:完毕生成项目,然后在类库的bin目录下就自动生成了这个自定义控件的dll文件. 2.在需要使用这个自定义控件的项目里,直接ctrl+c,c ...
- Postman的基础使用
postman的基础功能,官方文档介绍的是相当啰嗦,所以笔者这里先简单介绍一下主界面,入门功能就都提到了.稍后我们再一一介绍基础功能的使用方法. Collections:在Postman中,Colle ...
- UVA699-落叶-二叉树
1:用一根数轴,根结点是坐标index,左结点-1,右结点+1 还有一个0ms的不知道怎么过的 #include<stdio.h> #include<iostream> #in ...