1.使用tensorboard可视化ACC,loss等曲线
1 keras.callbacks.TensorBoard(log_dir=‘./Graph‘, 2 histogram_freq= 0 , 3 write_graph=True, 4 write_images=True) 5 tbCallBack = keras.callbacks.TensorBoard(log_dir=‘./Graph‘, 6 histogram_freq= 0, 7 write_graph=True, 8 write_images=True) 9 … 10 … 11 model.compile(optimizer=optim, 12 loss=MultiboxLoss(NUM_CLASSES, neg_pos_ratio=2.0).compute_loss, metrics=[‘accuracy‘]) 13 nb_epoch = 30 14 history = model.fit_generator(gen.generate(True), gen.train_batches, 15 nb_epoch, verbose=1, 16 callbacks=[tbCallBack], 17 validation_data=gen.generate(False), 18 nb_val_samples=gen.val_batches, 19 nb_worker=1)
然后新开一个终端
输入:
tensorboard --logdir path_to_current_dir/Graph
之后打开终端给出的网址即可。
2.直接使用matplotlib画出训练LOSS与ACC曲线
第一步:
1 # define the function 2 def training_vis(hist): 3 loss = hist.history[‘loss‘] 4 val_loss = hist.history[‘val_loss‘] 5 acc = hist.history[‘acc‘] 6 val_acc = hist.history[‘val_acc‘] 7 8 # make a figure 9 fig = plt.figure(figsize=(8,4)) 10 # subplot loss 11 ax1 = fig.add_subplot(121) 12 ax1.plot(loss,label=‘train_loss‘) 13 ax1.plot(val_loss,label=‘val_loss‘) 14 ax1.set_xlabel(‘Epochs‘) 15 ax1.set_ylabel(‘Loss‘) 16 ax1.set_title(‘Loss on Training and Validation Data‘) 17 ax1.legend() 18 # subplot acc 19 ax2 = fig.add_subplot(122) 20 ax2.plot(acc,label=‘train_acc‘) 21 ax2.plot(val_acc,label=‘val_acc‘) 22 ax2.set_xlabel(‘Epochs‘) 23 ax2.set_ylabel(‘Accuracy‘) 24 ax2.set_title(‘Accuracy on Training and Validation Data‘) 25 ax2.legend() 26 plt.tight_layout()
第二步:
1 # train the model 2 hist = model.fit(...)
第三步:
1 # call the function 2 training_vis(hist)
原文地址:https://www.cnblogs.com/tectal/p/9426994.html
时间: 2024-10-09 14:24:37