通过相关资料,学习使用TensorFlow搭建CNN的流程。整的提出分为以下几个步骤:设置网络参数—设置输入占位符变量—设置网络结构—优化损失函数—设置训练参数—训练网络—输出准确度等
#!/usr/bin/env python
# encoding: utf-8
'''
@author: Great
@file: CNN_practice.py
@time: 2018/11/26 17:50
@desc: 在此写上代码文件的功能描述
'''
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
#网络超参数
learning_rate = 0.001
training_epochs = 20000
batch_size = 128
display = 100
#网络参数
n_input = 784
n_classes = 10
dropout = 0.75
#占位符
x = tf.placeholder(tf.float32, shape = [None, 784], name = "input")
y = tf.placeholder(tf.float32, shape=[None, 10], name="output")
keep_prob = tf.placeholder(tf.float32)
#网络模型
#卷积操作
def conv2d(name, x, W, b, strides=1):
x = tf.nn.conv2d(x,W,strides=[1,strides,strides,1], padding="SAME")
x