tensorboardx--scalar

train.py

from tensorboardX import SummaryWriter 
from opts import parser                                                         
args=parser.parse_args()                                                        
model_name=args.model_name  
a=datetime.datetime.now()                                                       
b=datetime.datetime.strftime(a,'-%Y-%m-%d-%H-%M-%S')                            
n_model_name=model_name+b   
writer = SummaryWriter('runs/'+model_name+'/'+n_model_name)   
writer.add_scalar('data/trainloss', epoch_loss, epoch)                                                                                
writer.add_scalar('data/trainacc', epoch_acc, epoch)                                                                        
writer.add_scalar('data/valloss', epoch_loss, epoch)            
writer.add_scalar('data/valacc', epoch_acc, epoch)
writer.export_scalars_to_json("./all_scalars.json")                         
writer.close()

opts.py

 import argparse                                                                                                                                       
parser = argparse.ArgumentParser(description="PyTorch implementation of Temporal Segment Networks")
parser.add_argument('--model_name',type=str)  

watch

tensorboard --logdir runs --port 66

你可能感兴趣的:(tensorboardx--scalar)