Open ChenSiwiI opened 1 year ago
l update the train.py code 2023-04-22 12:50 updated :
l update the train.py code 2023-04-22 12:50 updated :
add log.txt file
- include nc, model information
- include Dloss and Gloss and auc and lr at each epoch
thanks!
In def train_epochs(model,train_loader,test_loader,args): at train.py , try to implement draw plot of auc and loss at each epochs, but failed...
#============================
# Initialize list for draw plots
#============================
GlossTr_list=[] #New add code
auc_val_list=[] #New add code
epoches = [] #New add code
#==================================
for epoch in range(1, args.epoch+1):
train_loss = 0.0
G_loss = 0
D_loss = 0
....
GlossTr_list.append(avg_g_loss) #New add code
epoches.append(epoch) #New add code
...
#calculate auc
auc = model.test(test_loader)
auc_val_list.append(auc) #New add code
print('auc = {:.6f}'.format(auc))
#==========================================================
# Below code implement : Plot the figures at each epochs (New add code)
#=============================================================
fig1, ax1 = plt.subplots(figsize=(11, 8))
ax1.plot(epoches, GlossTr_list)
ax1.set_title("Average training Gloss vs epochs")
ax1.set_xlabel("Epochs")
ax1.set_ylabel("Current Gloss")
print(args.save_dir)
plt.savefig(args.save_dir,"loss_vs_epochs.png")
plt.clf()
fig2, ax2 = plt.subplots(figsize=(11, 8))
ax2.plot(epoches, auc_val_list, label="Val auc")
ax2.set_title("Average AUC vs epochs")
ax2.set_xlabel("Epochs")
ax2.set_ylabel("Current AUC")
plt.legend(loc='lower right')
plt.savefig(args.save_dir + "auc_vs_epochs.png")
plt.close('all')
up code try to draw plot of loss-epoch and auc-epoch, but have errors, l also update this code, but noted (do not use now) sorry
l update the train.py code 2023-04-22 12:50 updated :l更新train.py代码2023-04-22 12:50更新:
add log.txt file 添加log.txt文件
- include nc, model information 包括NC、模型信息
- include Dloss and Gloss and auc and lr at each epoch包括在每个时期Dloss和Gloss以及auc和lr
thanks! 谢谢!
In def train_epochs(model,train_loader,test_loader,args): at train.py , try to implement draw plot of auc and loss at each epochs, but failed...在def train_epochs(model,train_loader,test_loader,args)中:在train.py,尝试实现绘制每个epoch的auc和loss的图,但失败了...
#============================ # Initialize list for draw plots #============================ GlossTr_list=[] #New add code auc_val_list=[] #New add code epoches = [] #New add code #================================== for epoch in range(1, args.epoch+1): train_loss = 0.0 G_loss = 0 D_loss = 0 .... GlossTr_list.append(avg_g_loss) #New add code epoches.append(epoch) #New add code ... #calculate auc auc = model.test(test_loader) auc_val_list.append(auc) #New add code print('auc = {:.6f}'.format(auc)) #========================================================== # Below code implement : Plot the figures at each epochs (New add code) #============================================================= fig1, ax1 = plt.subplots(figsize=(11, 8)) ax1.plot(epoches, GlossTr_list) ax1.set_title("Average training Gloss vs epochs") ax1.set_xlabel("Epochs") ax1.set_ylabel("Current Gloss") print(args.save_dir) plt.savefig(args.save_dir,"loss_vs_epochs.png") plt.clf() fig2, ax2 = plt.subplots(figsize=(11, 8)) ax2.plot(epoches, auc_val_list, label="Val auc") ax2.set_title("Average AUC vs epochs") ax2.set_xlabel("Epochs") ax2.set_ylabel("Current AUC") plt.legend(loc='lower right') plt.savefig(args.save_dir + "auc_vs_epochs.png") plt.close('all')
up code try to draw plot of loss-epoch and auc-epoch, but have errors, l also update this code, but noted (do not use now) sorry上代码尝试绘制损失时期和auc-epoch图,但有错误,我也更新了此代码,但注意到(现在不使用)抱歉
Thank you. But each test will encounter the following situations:
3 Start normal AE:
loss : 2.254371166229248
24 Start normal AE:
loss : 5.585793495178223
25 Start normal AE:
loss : 4.096798419952393
26 Start normal AE:
loss : 88.05529022216797
Traceback (most recent call last):
File "F:/Skip-CBAM-SelfAttention-GANomaly-Pytorch-main/test.py", line 212, in
I want to know if the program was forced to interrupt at a certain step? And there is no record of loss in the test~
did you set the batch_size 1 ? For example command : python test.py --batch-size 1 --normal xxx --abnormal xxx ...
I would like to ask if there is a txt file to save the loss during training and testing, and can it be visualized