神经网络的训练的大致流程

batch_size = n

# 每次读取一小部分数据作为当前的训练数据来执行反向传播算法
x = tf.placeholder(tf.float32, shape=(batch_size, feature_num), name="x-input")
y_= tf.placeholder(tf.float32, shape=(batch_size, 1), name='y-input')

# 定义神经网络结构和优化算法
loss = ...
# loss = -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)))    ## cross_entropy(交叉熵)
learning_rate = 0.001

#定义反向传播算法 
train_step = tf.train.AdamOptimizer(learning_rate).minimize(loss)  # 优化算法

# 训练神经网络
with tf.Session() as sess:
    # 参数初始化
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    
    ...
    
    # 训练模型。
    STEPS = ...
    # 迭代的更新参数
    for i in range(STEPS):
        # 准备batch_size个训练数据。一般将所有训练数据打乱之后再选取可以得到更好的优化效果。
        current_X, current_Y = ...
        # 对`tf.GraphKeys.TRAINABLE_VARIABLES`集合中的变量进行优化,使得当前batch下损失最小
        sess.run(train_step, feed_dict = {x : current_X, y : current_Y})
原文地址:https://www.cnblogs.com/q735613050/p/7779994.html