99网
您的当前位置:首页TensorFlow实现基础CNN,两层卷积+2层全连接网络demo

TensorFlow实现基础CNN,两层卷积+2层全连接网络demo

来源:99网

TensorFlow实现基础CNN,两层卷积+2层全连接网络demo,代码如下,注释都有

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data

#加载数据集
mnist =input_data.read_data_sets( 'MNIST_data', one_hot = True)

#每个批次的大小
batch_size = 50

#共有xx个批次
n_batch =mnist.train.num_examples //batch_size

#初始化权重
def weight_variable( shape):
#生成shape结构的变量,方差=0.1
initial =tf.truncated_normal(shape, stddev = 0.1)
return tf.Variable(initial)

#初始化偏置
def bias_variable( shape):
initial =tf.constant( 0.1, shape =shape)
return

因篇幅问题不能全部显示,请点此查看更多更全内容