Tensorflow CNN 绘图学习率与准确率

Tensorflow CNN plot learning rate vs accuracy

我想实现循环 LR 方法(用于找到最佳学习率边界),这需要我绘制学习率与准确率的关系图。但是现在,我似乎无法正常工作。在训练模型时,下面的部分代码要么绘制一个空图,要么给我空列表,我不确定我是否误解了 TF 语言中的某些内容。

对代码的一点阐述(credits),在这段代码的上方,我创建了acc_list = []lr_list = []。这两个列表应该填充值,模型执行的每个全局步骤。所以我想将这些值附加到列表中,当模型完成后,将这两个列表绘制成图表,以找到学习率边界。 我必须做更多 'tf-coding' 吗?现在我认为 运行 sess 就足够了,因为这也给出了 current learning ratecurrent accuracy,因此值存在。

def run():
#Run the managed session
    with sv.managed_session() as sess:
        for step in range(num_steps_per_epoch * num_epochs):
            #At the start of every epoch, show the vital information:
            if step % num_batches_per_epoch == 0:
                logging.info('Epoch %s/%s', step/num_batches_per_epoch + 1, num_epochs)
                learning_rate_value, accuracy_value = sess.run([lr1, accuracy])
                logging.info('Current Learning Rate: %s', learning_rate_value)
                logging.info('Current Streaming Accuracy: %s', accuracy_value)


            #Log the summaries every 10 steps.
            if step % 10 == 0:
                loss, _ = train_step(sess, train_op, sv.global_step)
                summaries = sess.run(my_summary_op)
                sv.summary_computed(sess, summaries)
                iteration_step += 1

            #Run training if not 10 steps
            else:
                loss, _ = train_step(sess, train_op, sv.global_step)
                iteration_step += 1


            lr_list.append(sess.run([lr1]))
            acc_list.append(sess.run([accuracy]))

        #We log the final training loss and accuracy
        logging.info('Final Loss: %s', loss)
        logging.info('Final Accuracy: %s', sess.run(accuracy))

        plt.plot(lr_list, acc_list)

        #Once all the training has been done, save the log files and checkpoint model
        logging.info('Finished training! Saving model to disk now.')

        sv.saver.save(sess, sv.save_path, global_step = sv.global_step)


if __name__ == '__main__':
    run()

这里没有特定于 TF 的内容。 lr_list.append(sess.run([lr1])) 确实会将 lr1 张量的当前值附加到 lr_list。在这一点上是纯粹的Python。如果列表末尾为空,请像调试任何常规 python 代码一样调试它...例如确保这条线实际上达到了你预期的次数,确保在你向它添加内容和绘制它的值之间没有其他人改变列表。