最近在学习《tensorflow实战 Google深度学习框架》,虽然看资料的时候能明白其思想,但实践的时候经常会卡在其中的一些细节,故通过此文进行一个梳理。
这个简单的卷积神经网络包括以下几个内容:卷积、池化、全连接层,第六章开篇介绍的简单神经网络为例。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from tensorflow.examples.tutorials.mnist import input_data
minist = input_data.read_data_sets('tempt/', one_hot = True)
sess = tf.Session()
x = tf.placeholder(tf.float32, [None, 784])
y_ = tf.placeholder(tf.float32, [None, 10])
x_image = tf.reshape(x, [-1, 28, 28, 1])
W_conv1 = tf.Variable(tf.truncated_normal(shape = [5, 5, 1, 32], stddev = 0.1))
b_conv1 = tf.Variable(tf.constant(0.1, shape = [32]))
h_conv1 = tf.nn.relu(tf.add(tf.nn.conv2d(x_image, W_conv1, strides = [1, 1, 1, 1], padding = 'SAME'), b_conv1))
h_pool1 = tf.nn.max_pool(h_conv1, ksize = [1, 2, 2, 1], strides = [1, 2, 2, 1], paddin