zoukankan      html  css  js  c++  java
  • 神经网络的训练的大致流程

    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})
    
  • 相关阅读:
    Docker PHP 扩展配置
    PHP 打水印功能
    MYSQL的主从复制
    CentOS7开启防火墙及特定端口
    非常全面的讲解Hosts文件
    STL的erase()陷阱-迭代器失效总结
    scons使用
    SecureCRT 使用技巧
    atomic, spinlock and mutex性能比较
    内存池的实现(二)
  • 原文地址:https://www.cnblogs.com/q735613050/p/7779994.html
Copyright © 2011-2022 走看看