In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use tensorboard in Keras". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use tensorboard in Keras.
Method 1 (standard calling method):
Use fit () peculiar to keras for training, as long as you specify the callbacks function in fit, as follows
From keras.callbacks import TensorBoardfrom keras.models import Sequential... Model = Sequential (). TbCallBack = keras.callbacks.TensorBoard (log_dir='./Graph',histogram_freq=1,write_graph=True,write_images=True) model_history = model.fit (Xanzhongzhongzhongyuzhongjie batchengsizepai Paochui Paochui Paochzhong Paochizi, callbacks = (X_train_val, y_train_val) callbacks = [EarlyStopping (patience=patience,mode='min',verbose=1), history,tbCallBack]
Although this method looks beautiful, it only applies to standard training methods. If you want to use your own training method, you need to call train_on_batch instead of using fit () directly, then use the following method:
Method 2 (special calling method):
This method can be used in cases where train_on_batch is called.
% write writer in advance and define modelwriter = tf.summary.FileWriter (…) Model =... % training loss = model.train_on_batch (…) Summary = tf.Summary (value= [tf.Summary.Value (tag= "d_loss", simple_value=d_loss), tf.Summary.Value (tag= "g_loss", simple_value=g_loss),] writer.add_summary (summary)
Although it is very simple, this method can only display scalar types, not image,histgram, etc., which is very impractical. What is really practical is the following termination method:
Method 3 (the most practical method)
The most practical is to use the tensorflow native calling method, although it is a bit troublesome compared to method 2, but considering that this method, like tensorflow, does not need to remember those extra tricks, so it is the simplest and most effective.
The code is as follows:
Import tensorflow as tfimport datetime% pre-defines the visualization before the training starts, using the native tensorflow method. Here we take a GAN model as an example and let it display the whole model diagram, two scalar loss functions, and five generated images. The method is to declare the things to be displayed in advance with placeholder, and then populate them with the training results during the training process. You can join histgram by yourself. All are the same as tensorflow # start tensorboardsess=tf.Session () logdir = "tensorboard/" + datetime.datetime.now (). Strftime ("% Y%m%d-%H%M%S") + "/" writer = tf.summary.FileWriter (logdir, sess.graph) D_LOSS = tf.placeholder (tf.float32, []) G_LOSS = tf.placeholder (tf.float32, []) IMAGES = tf.placeholder (tf.float32,shape= [None,28,28,1]) tf.summary.scalar ("D_LOSS") D_LOSS) tf.summary.scalar ("G_LOSS", G_LOSS) tf.summary.image ("IMAGES", IMAGES, 5) merged=tf.summary.merge_all () # end tensorboard
In the iterative process of training, it goes like this.
For epoch in range:% use keras's train_on_batch method to train d_loss = d.train_on_batch (.) G_loss = d_on_g.train_on_batch (.) Generated_images = g.predict (.) If index==0: # tensorboard% populates the training results with visual data summary=sess.run (merged,feed_dict= {D_LOSS:d_loss, G_LOSS:g_loss, IMAGES:generated_images}) writer.add_summary (summary,index)
Thank you for your reading, the above is the content of "how to use tensorboard in Keras", after the study of this article, I believe you have a deeper understanding of how to use tensorboard in Keras, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.