用keras框架搭建神经网络 ——(三)识别手写数字

今天进阶到手写识别神经网络的搭建。
源代码:https://download.csdn.net/download/rance_king/11010836

  1. 导入包
import numpy as np
import matplotlib.pyplot as plt
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam
from keras.utils.np_utils import to_categorical
import random
np.random.seed(0)
  1. 导入数据并确认数据格式正确,这里有个附加的知识点,使用assert语法来鉴别数据的格式正确,如果正确则放行,如果不正确则报错。
(X_train, y_train), (X_test, y_test) = mnist.load_data()
assert(X_train.shape[0] ==  y_train.shape[0]), "The number of images is not equal to the number of labels."
assert(X_test.shape[0] == y_test.shape[0]), "The number of images is not equal to the number of labels."
assert(X_train.shape[1:] == (28,28)), "The dimensions of the images are not 28x28"
assert(X_test.shape[1:] == (28,28)), "The dimensions of the images are not 28x28"
  1. 接下来将可视化拿下来的数据集,用比较好看的格式将数据集中的图片内容呈现出来。
#我想查看一下这个数据集里面每个标签下有多少个样本,用空数组接收后面被放入的每个标签下样本数量
num_of_samples = []
 
cols = 
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值