import time

import keras
from keras.utils import np_utils start = time.time()
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
rows = 28
cols = 28
CLASSES = 10
x_train = x_train.reshape(x_train.shape[0], rows, cols, 1)
x_test = x_test.reshape(x_test.shape[0], rows, cols, 1)
y_train = np_utils.to_categorical(y_train, CLASSES)
y_test = np_utils.to_categorical(y_test, CLASSES) x_train = x_train.astype("float32")
x_test = x_test.astype("float32")
x_train /= 255
x_test /= 255 model = keras.models.Sequential([
keras.layers.Conv2D(16, (3, 3), activation='relu', input_shape=x_train.shape[1:]),
keras.layers.MaxPool2D(pool_size=(2, 2)),
keras.layers.Conv2D(32, (3, 3), activation='relu'),
keras.layers.Conv2D(64, (3, 3), activation='relu'),
keras.layers.Flatten(),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dropout(0.5),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dropout(0.5),
keras.layers.Dense(10, activation='softmax')
])
model.summary()
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=64, epochs=5)
evaluate = model.evaluate(x_test, y_test)
print(evaluate)
print("elapsed: ", time.time() - start)
model.save("mnist-con.h5")

  

keras基于卷积网络手写数字识别的更多相关文章

  1. keras框架的MLP手写数字识别MNIST,梳理?

    keras框架的MLP手写数字识别MNIST 代码: # coding: utf-8 # In[1]: import numpy as np import pandas as pd from kera ...

  2. 【机器学习】李宏毅机器学习-Keras-Demo-神经网络手写数字识别与调参

    参考: 原视频:李宏毅机器学习-Keras-Demo 调参博文1:深度学习入门实践_十行搭建手写数字识别神经网络 调参博文2:手写数字识别---demo(有小错误) 代码链接: 编程环境: 操作系统: ...

  3. TensorFlow 卷积神经网络手写数字识别数据集介绍

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 手写数字识别 接下来将会以 MNIST 数据集为例,使用卷积层和池 ...

  4. 深度学习-使用cuda加速卷积神经网络-手写数字识别准确率99.7%

    源码和运行结果 cuda:https://github.com/zhxfl/CUDA-CNN C语言版本参考自:http://eric-yuan.me/ 针对著名手写数字识别的库mnist,准确率是9 ...

  5. 基于opencv的手写数字识别(MFC,HOG,SVM)

    参考了秋风细雨的文章:http://blog.csdn.net/candyforever/article/details/8564746 花了点时间编写出了程序,先看看效果吧. 识别效果大概都能正确. ...

  6. keras实现mnist数据集手写数字识别

    一. Tensorflow环境的安装 这里我们只讲CPU版本,使用 Anaconda 进行安装 a.首先我们要安装 Anaconda 链接:https://pan.baidu.com/s/1AxdGi ...

  7. keras框架的CNN手写数字识别MNIST

    参考:林大贵.TensorFlow+Keras深度学习人工智能实践应用[M].北京:清华大学出版社,2018. 首先在命令行中写入 activate tensorflow和jupyter notebo ...

  8. keras—神经网络CNN—MNIST手写数字识别

    from keras.datasets import mnist from keras.utils import np_utils from plot_image_1 import plot_imag ...

  9. OpenCV+TensorFlow图片手写数字识别(附源码)

    初次接触TensorFlow,而手写数字训练识别是其最基本的入门教程,网上关于训练的教程很多,但是模型的测试大多都是官方提供的一些素材,能不能自己随便写一串数字让机器识别出来呢?纸上得来终觉浅,带着这 ...

随机推荐

  1. Vue--理解非prop特性

    所谓非 prop 特性,就是指它可以直接传入组件,而不需要定义相应的 prop. 尽管为组件定义明确的 prop 是推荐的传参方式,组件的作者却并不总能预见到组件被使用的场景.所以,组件可以接收任意传 ...

  2. PAT A1046 Shortest Distance (20 分)

    题目提交一直出现段错误,经过在网上搜索得知是数组溢出,故将数组设置的大一点 AC代码 #include <cstdio> #include <algorithm> #defin ...

  3. sql之游标

    --select * from   master..sysprocessesuse testdeclare my_cursor cursor scroll dynamic --scroll表示可以向前 ...

  4. Dom编程-左侧菜单栏设计模型实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. webpack提取图片文件打包压缩

    抽离图片文件打包到指定路径下 压缩抽离的图片资源 配置生成html中的图片路径 一.准备测试环境 //工作区间 src//文件夹 index.js//入口文件 index.css//样式文件 inde ...

  6. 微信小程序页面跳转传参方式

    //实现跳转的A页面 jump: function () { let a = 1; let b = 2; wx.navigateTo({ url: '/page/vipOrder/vipOrder?d ...

  7. 不错的abap技术网站

    http://www.saptechnical.com/index.htm https://sapcodes.com/

  8. Spring与junit4集成测试

    一.应用场景:普通java web集成spring test, 项目结构:使用的是加入jar的方式,不是maven加入依赖的方式 注意:如果是引入jar包的方式,例如:spring-test4.0.5 ...

  9. 工作总结 [ActionName("ss123")] 更改路由中Action名称 获取或设置操作的名称

  10. JavaJDBC【五、事务】

    概念: 事务(Transaction)作为单个逻辑工作单元执行的一系列操作. 这些操作都是作为一个整体一起向系统提交,要么都执行,要么都不执行. 特点: 原子性:一个完整操作. 一致性:当事务完成时, ...