用卷积神经网络实现手写字体的识别

编程入门 行业动态 更新时间:2024-10-08 08:29:48

用<a href=https://www.elefans.com/category/jswz/34/1765938.html style=卷积神经网络实现手写字体的识别"/>

用卷积神经网络实现手写字体的识别

代码如下所示:
# -*- coding: utf-8 -*-
# @Time    : 2018/4/4 13:22
# @Author  : mgliu
# @FileName: mnist.py
# @Software: PyCharm Community Edition
# -*- coding: utf-8 -*-

import numpy as np
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D
(X_train,y_train),(X_test,y_test)=mnist.load_data()
print(X_train.shape)
print(y_train[0])
X_train=X_train.reshape(X_train.shape[0],28,28,1).astype('float32')
X_test=X_test.reshape(X_test.shape[0],28,28,1).astype('float')
X_train/=255
X_test/=255
#把标签用one-hot 从新编码
def tran_y(y):y_ohe=np.zeros(10)y_ohe[y]=1
    return y_ohe
y_train_ohe=np.array([tran_y(y_train[i])for i in range(len(y_train))])
y_test_ohe=np.array([tran_y(y_test[i])for i in 

更多推荐

用卷积神经网络实现手写字体的识别

本文发布于:2024-02-07 01:57:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1752187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:卷积   神经网络   字体

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!