标题介绍运行环境了win7

看网上好多keras识别minist 但是一般由于版本问题,无法直接用,,,这里还要特别感谢keras中文文档作者(三当家SCP)。教程整的非常好。还有就是最好你在安装anaconda 之前把原来安装过的PY卸载掉,要不然安装mingw的时候会出问题,,,安装就不详细介绍了网上有很多种----大致流程——anaconda-mingw-theano(注意环境变量,系统变量啥的)-keras。

下边附上一个可用程序哈,亲测可用。。。并附上数据,数据来源于网络,见文章底部,你就不用运行的时候在下载数据,这样很容易出错的。非GPU环境 win7 64bit

好的:其实重点是新的语法的问题。。。。。。。。。。。。。。。。。。。更新地方已标红。。。。。。。

  1. from __future__ import absolute_import
  2. from __future__ import print_function
  3. import numpy as np
  4. np.random.seed(1337) # for reproducibility
  5. import cPickle as pickle
  6.  
  7. from keras.models import Sequential
  8. from keras.layers.core import Dense, Dropout, Activation
  9. from keras.optimizers import SGD, Adam, RMSprop
  10. from keras.utils import np_utils
  11.  
  12. '''
  13. Train a simple deep NN on the MNIST dataset.
  14. Get to 98.30% test accuracy after 20 epochs (there is *a lot* of margin for parameter tuning).
  15. 2 seconds per epoch on a GRID K520 GPU.
  16. '''
  17.  
  18. batch_size = 128
  19. nb_classes = 10
  20. nb_epoch = 10
  21.  
  22. def read_data(data_file):
  23. 24 import gzip
  24. 25 f = gzip.open(data_file, "rb")
  25. 26 train, val, test = pickle.load(f)
  26. 27 f.close()
  27. 28 train_x = train[0]
  28. 29 train_y = train[1]
  29. 30 test_x = test[0]
  30. 31 test_y = test[1]
  31. 32 return train_x, train_y, test_x, test_y
  32.  
  33. # the data, shuffled and split between tran and test sets
  34. #(X_train, y_train), (X_test, y_test) = mnist.load_data()
  35. train_x, train_y, test_x, test_y = read_data("C:\Users\PC\.spyder2\mnist.pkl.gz")
  36. X_train = train_x
  37. X_test = test_x
  38. X_train = X_train.astype("float32")
  39. X_test = X_test.astype("float32")
  40. X_train /= 255
  41. X_test /= 255
  42. print(X_train.shape[0], 'train samples')
  43. print(X_test.shape[0], 'test samples')
  44.  
  45. # convert class vectors to binary class matrices
  46. Y_train = np_utils.to_categorical(train_y, nb_classes)
  47. Y_test = np_utils.to_categorical(test_y, nb_classes)
  48.  
  49. model = Sequential()
  50. model.add(Dense(input_dim=784, output_dim=128))
  51. 53 model.add(Activation('relu'))
  52. 54 model.add(Dropout(0.2))
  53. 55 model.add(Dense(output_dim=128))
  54. 56 model.add(Activation('relu'))
  55. 57 model.add(Dropout(0.2))
  56. 58 model.add(Dense(output_dim=10))
  57. 59 model.add(Activation('softmax'))
  58.  
  59. rms = RMSprop()
  60. model.compile(loss='categorical_crossentropy', optimizer=rms,metrics=['accuracy'])
  61. 63
  62. 64 model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch)
  63. 65 score = model.evaluate(X_test, Y_test, batch_size=batch_size)
  64. print('Test score:', score[0])
  65. print('Test accuracy:', score[1])

数据在这里:http://www.cnblogs.com/xueliangliu/archive/2013/04/03/2997437.html。。。由于没法上传有15兆,我看这个大牛有这个数据,而且还附带了安装及原理等,自己看吧。。。。。。。

anaconda+theano+keras手写字符识别新版的更多相关文章

  1. 李宏毅 Keras手写数字集识别(优化篇)

    在之前的一章中我们讲到的keras手写数字集的识别中,所使用的loss function为‘mse’,即均方差.那我们如何才能知道所得出的结果是不是overfitting?我们通过运行结果中的trai ...

  2. 仅用200个样本就能得到当前最佳结果:手写字符识别新模型TextCaps

    由于深度学习近期取得的进展,手写字符识别任务对一些主流语言来说已然不是什么难题了.但是对于一些训练样本较少的非主流语言来说,这仍是一个挑战性问题.为此,本文提出新模型TextCaps,它每类仅用200 ...

  3. 100天搞定机器学习|day39 Tensorflow Keras手写数字识别

    提示:建议先看day36-38的内容 TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edge ...

  4. 【问题解决方案】Keras手写数字识别-ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接

    参考:台大李宏毅老师视频课程-Keras-Demo 在载入数据阶段报错: ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接 Google之 ...

  5. ubuntu 16.04+Anaconda+theano+keras安装【转】

    本文转载自:https://blog.csdn.net/u013786021/article/details/78370138 安装软件部分浪费了好长时间才装好.之前一直各种问题,后来卸卸了radin ...

  6. 利用Tensorflow实现手写字符识别

    模式识别领域应用机器学习的场景非常多,手写识别就是其中一种,最简单的数字识别是一个多类分类问题,我们借这个多类分类问题来介绍一下google最新开源的tensorflow框架,后面深度学习的内容都会基 ...

  7. Caffe2 手写字符识别(MNIST - Create a CNN from Scratch)[8]

    本教程创建一个小的神经网络用于手写字符的识别.我们使用MNIST数据集进行训练和测试.这个数据集的训练集包含60000张来自500个人的手写字符的图像,测试集包含10000张独立于训练集的测试图像.你 ...

  8. Keras手写识别例子(1)----softmax

    转自:https://morvanzhou.github.io/tutorials/machine-learning/keras/2-2-classifier/#测试模型 下载数据: # downlo ...

  9. keras手写数字识别

    import kerasimport timefrom keras.utils import np_utils start = time.time()(x_train, y_train), (x_te ...

随机推荐

  1. 拼图游戏js

    实现算法: 1. JavaScript动态生成拼图:通过生成16个div,且除最后一个div不使用背景图片以外,其他div都设置拼图图片为背景.然后通过调整background-position来实现 ...

  2. centos7 设置系统时间与网络同步

    1.安装ntpdate工具 yum -y install ntp ntpdate 2.设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org 3.将系统时间写入硬件时间 hwclo ...

  3. 使用oracle导出的dmp文件(包含表结构还是表数据?)

    我们都知道oracle提供了一个exp程序,可以导出dmp文件,那么dmp文件中到底包含哪些东西呢? 1:有对象的信息吗?比如对象的权限? 2:有表空间信息吗? 3:有表结构吗? 4:有表的索引和触发 ...

  4. oracle 所有 hint(转)

    oracle 10g 有64个hints , 11g 增加到71 个, 下表中红色的代表已经过时的, 粗体的是11g 新增. Optimization Goals and Approaches (2) ...

  5. 深度学习中的Normalization模型

    Batch Normalization(简称 BN)自从提出之后,因为效果特别好,很快被作为深度学习的标准工具应用在了各种场合.BN 大法虽然好,但是也存在一些局限和问题,诸如当 BatchSize ...

  6. pure框架

    内容: 1.介绍与入门 2.基础使用 参考资料: pure中文文档:https://www.purecss.cn/ pure实例:https://www.purecss.cn/layouts.html ...

  7. UVA-10115

    字符查找替换,WA了N次,一次只能替换一个,下一次find必须从第0个位置开始 import java.io.File; import java.io.FileNotFoundException; i ...

  8. saltstack安装配置及常用命令

    1.salt安装及配置详解 https://www.cnblogs.com/lgeng/p/6567424.html centos7配置: https://www.jianshu.com/p/4c91 ...

  9. 【独家】完美解决appium安装app时,需要手动确认安装的问题

    appium初始化driver时,如果未安装该app会先进行安装,安装时,很多安卓手机都会弹框,需要手动确认安装. 如小米的机器, 这是个头疼的问题,之前在网上找遍了,只有通过adb去点相对坐标成功了 ...

  10. 你该知道的 TValue

    你该知道的 TValue Represents a lightweight version of the Variant type. TValue is a data structure that c ...