keras中使用MLP(多层感知机)神经网络来实现MNIST手写体识别

    Keras是一个基于python的的深度学习框架,比tensorflow更简单易用,适合入门学习,本篇文章主要介绍使用keras实现手写体识别任务。环境为python3+,Keras2.1,神经网络基础知识在此不做过多介绍。

    1.    加载MNIST数据。

            方式一:from keras.datasets import mnist

    (X_train, y_train), (X_test, y_test) = mnist.load_data()

    print("The MNIST database has a training set of %d examples." % len(X_train))
    print("The MNIST database has a test set of %d examples." % len(X_test))



        方式二:方式一有可能加载失败,可以直接下载数据mnist.npz(文末有链接,可直接下载),放在当前目录下,使用numpy进行加载:

import numpy as np
f = np.load('mnist.npz')
x_train, y_train = f['x_train'], f['y_train']  
x_test, y_test = f['x_test'], f['y_test']  
f.close() 
print('训练数据集样本数: %d ,标签个数 %d ' % (len(x_train), len(y_train)))
print('测试数据集样本数: %d ,标签个数  %d ' % (len(x_test), len(y_test)))

print(x_train.shape)
print(y_train[0])

    输出如下:

        

    2.    使用matplotlib查看前六张图片:

import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib.cm as c
  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值