zoukankan      html  css  js  c++  java
  • tensorboard的使用

    1、keras 与 tensorboard

    from tensorflow.keras.callbacks import TensorBoard
    filepath="snapshot/v2_weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5" tensorboard = TensorBoard(log_dir='logs/{}'.format(filepath)) callbacks_list = [checkpoint, tensorboard] model.fit(train_imgs, train_labels, validation_data=(test_imgs, test_labels) , batch_size=256, callbacks=callbacks_list, epochs=15, shuffle=True, verbose=0)

     终端  tensorboard --logdir="./log"

       http://localhost:6006(如果访问的是服务器,别忘记修改ip)

       https://stackoverflow.com/questions/42112260/how-do-i-use-the-tensorboard-callback-of-keras

        更多参考:http://nooverfit.com/wp/tensorboard%E4%B8%8A%E6%89%8B%EF%BC%8Ctensorboard%E5%8F%AF%E8%A7%86%E5%8C%96%E6%99%AE%E5%8F%8A%E8%B4%B4%EF%BC%88%E4%BB%A3%E7%A0%81%E5%9F%BA%E4%BA%8Etensorflow1-2%E4%BB%A5%E4%B8%8A%EF%BC%89/

                              https://zhuanlan.zhihu.com/p/33178205

                           https://zhuanlan.zhihu.com/p/36946874

                          https://zhuanlan.zhihu.com/p/37022051

         

         监督的信息主要包括lr, acc,loss等

          

    # 静态流图
    summary_writer = tf.summary.FileWriter(train_dir, sess.graph)
    # 动态scalars
    tf.summary.scalar("loss", loss)
    tf.summary.scalar("accuracy", acc)
    
    with tf.name_scope("input_shape"):
        image_shape_input = tf.reshape(x, [-1, 100, 100, 3])
        tf.summary.image('input', image_shape_input, 2)
    
    summary_op = tf.summary.merge_all()
    
     # 记录耗时信息
        run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
        run_metadata = tf.RunMetadata()
    
        _, summary, train_loss, train_acc = sess.run([train_op, summary_op, loss, acc],
                                                     feed_dict={x: x_train_a, y_: y_train_a},
                                                     options=run_options,
                                                     run_metadata=run_metadata)
        end = time.time()
        summary_writer.add_run_metadata(run_metadata, 'step %04d' % steps)
        summary_writer.add_summary(summary, steps)

    2、模型可视化

         pb模型可视化 

    v1 = tf.Variable(tf.constant(1, shape=[1]), name='v1')
    v2 = tf.Variable(tf.constant(1, shape=[1]), name='v2')
    result = v1 + v2
    
    
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        graph = tf.get_default_graph()
        graph_def = graph.as_graph_def()
        output_grapg_def = tf.graph_util.convert_variables_to_constants(sess, graph_def, ["add"])
    
        with tf.gfile.GFile("Model/freeze_model.pb", 'wb') as f:
            f.write(output_grapg_def.SerializeToString())
    
        graph_def.ParseFromString(tf.gfile.GFile("Model/freeze_model.pb", 'rb').read())
        tf.import_graph_def(graph_def, name='graph')
        summary_writer = tf.summary.FileWriter('log/', graph)

        meta可视化

        

    v1 = tf.Variable(tf.constant(1, shape=[1]), name='v1')
    v2 = tf.Variable(tf.constant(1, shape=[1]), name='v2')
    result = v1 + v2
    
    saver = tf.train.Saver()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        print(sess.run(result))
        saver.save(sess, "Model/model.ckpt")
    
        graph = tf.get_default_graph()
        graph_def = graph.as_graph_def()
        _ = tf.train.import_meta_graph("Model/model.ckpt.meta")
        summary_writer = tf.summary.FileWriter("log/", graph)
  • 相关阅读:
    中文排版指南
    HTTP返回码详解
    我的JS 类 写法
    【CodeForces】[630C]Lucky Numbers
    【CodeForces】[630C]Lucky Numbers
    【CodeForces】[630A]Again Twenty Five!
    【CodeForces】[630A]Again Twenty Five!
    【HPU】[1006]DNA
    【HPU】[1006]DNA
    【杭电】[3790]最短路径问题
  • 原文地址:https://www.cnblogs.com/573177885qq/p/10819102.html
Copyright © 2011-2022 走看看