使用卷积神经网络对mnist数据集进行分析
使用tensorflow对mnist数据集进行建模
#1、导入需要用到的包
import tensorflow as tf
import random
import numpy as np
import matplotlib.pyplot as plt
import datetime
from tensorflow.examples.tutorials.mnist import input_data
#2、导入mnist数据集
mnist = input_data.read_data_sets("data/", one_hot=True)
#3、定义x和y,即输入x和标签y
tf.reset_default_graph()
sess = tf.InteractiveSession()
x = tf.placeholder("float", shape = [None, 28,28,1]) #输入是28x28、通道是1的图片
y_ = tf.placeholder("float", shape = [None, 10]) #输出是一个10维的向量,表示10个分类
W_conv1 = tf.Variable(tf.truncated_normal([5, 5, 1, 32], stddev=0.1)) #第一层的卷积,大小是5x5,数量是32个
b_conv1 = tf.Variable(tf.constant(.1, shape = [32])) #第一层的偏置,大小是32
#4、建立第一层卷积层