save_out = output netD.zero_grad() errD_real = criterion(output, labelv) errD_real.backward() D_x = errD_real.data.mean() optimizerD.step() # train with fake if cv2.waitKey(12) & 0xFF == ord('q'): break print('[%d/%d][%d/%d] Loss_D: %.4f Loss_G: %.4f D(x): %.4f D(G(z)): %.4f / %.4f' % (epoch, 0, read_id, 0, errD_real.data, D_x, 0, 0, 0)) if Visdom_flag == True: plotter.plot( 'LOSS', 'LOSS', 'LOSS', iteration_num, D_x.cpu().detach().numpy()) if read_id % 2 == 0: #vutils.save_image(real_cpu, # '%s/real_samples.png' % opt.outf, # normalize=True) #netG.eval() #fake = netG(fixed_noise) #cv2.imwrite(Save_pic_dir + str(i) +".jpg", mat) #show the result dispay_id =0 Matrix = mydata_loader.input_mat[dispay_id,0,:,:] +104 show1 = Matrix*0 path2 = (mydata_loader.input_path[dispay_id,:])*Original_window_Len show1[int(path2[0]),:]=254
#optimizerG.step() #save_out = Fake # train with fake # if cv2.waitKey(12) & 0xFF == ord('q'): # break print (" all test point time is [%f] " % ( test_time_point - start_time)) if validation_flag==False: print('[%d/%d][%d/%d] Loss_D: %.4f Loss_G: %.4f D(x): %.4f D(G(z)): %.4f / %.4f' % (epoch, 0, read_id, 0, G_x, D_x, 0, 0, 0)) if read_id % 2 == 0 and Visdom_flag == True and validation_flag==False: plotter.plot( 'DLOSS', 'DLOSS', 'DLOSS', iteration_num, D_x.cpu().detach().numpy()) plotter.plot( 'GLOSS', 'GLOSS', 'GLOSS', iteration_num, G_x.cpu().detach().numpy()) plotter.plot( 'GlLOSS', 'GlLOSS', 'GlLOSS', iteration_num, G_x_L12.cpu().detach().numpy()) #plotter.plot( 'cLOSS1', 'cLOSS1', 'cLOSS1', iteration_num, D_x1.cpu().detach().numpy()) #plotter.plot( 'cLOSS12', 'cLOSS2', 'cLOSS2', iteration_num, D_x2.cpu().detach().numpy()) #plotter.plot( 'cLOSS_f', 'cLOSSf', 'cLOSSf', iteration_num, D_xf.cpu().detach().numpy()) if read_id % 1 == 0 and Display_fig_flag== True: #vutils.save_image(real_cpu, # '%s/real_samples.png' % opt.outf, # normalize=True) #netG.eval() #fake = netG(fixed_noise) #cv2.imwrite(Save_pic_dir + str(i) +".jpg", mat) #show the result
D_xf = errD_real_fuse.data.mean() optimizerD.step() save_out = output2 # train with fake # if cv2.waitKey(12) & 0xFF == ord('q'): # break print('[%d/%d][%d/%d] Loss_D: %.4f Loss_G: %.4f D(x): %.4f D(G(z)): %.4f / %.4f' % (epoch, 0, read_id, 0, errD_real.data, D_x, 0, 0, 0)) if read_id % 20 == 0 and Visdom_flag == True: plotter.plot( 'cLOSS', 'cLOSS', 'cLOSS', iteration_num, D_x.cpu().detach().numpy()) plotter.plot( 'cLOSS1', 'cLOSS1', 'cLOSS1', iteration_num, D_x1.cpu().detach().numpy()) plotter.plot( 'cLOSS12', 'cLOSS2', 'cLOSS2', iteration_num, D_x2.cpu().detach().numpy()) plotter.plot( 'cLOSS_f', 'cLOSSf', 'cLOSSf', iteration_num, D_xf.cpu().detach().numpy()) if read_id % 1 == 0 and Display_fig_flag== True: #vutils.save_image(real_cpu, # '%s/real_samples.png' % opt.outf, # normalize=True) #netG.eval() #fake = netG(fixed_noise) #cv2.imwrite(Save_pic_dir + str(i) +".jpg", mat) #show the result gray2 = (mydata_loader.input_image[0,0,:,:] *104)+104 show1 = gray2.astype(float)
#optimizerG.step() #save_out = Fake # train with fake # if cv2.waitKey(12) & 0xFF == ord('q'): # break if validation_flag==False: print('[%d/%d][%d/%d] Loss_D: %.4f Loss_G: %.4f D(x): %.4f D(G(z)): %.4f / %.4f' % (epoch, 0, read_id, 0, G_x, D_x, 0, 0, 0)) if read_id % 2 == 0 and Visdom_flag == True and validation_flag==False: plotter.plot( 'l0', 'l0', 'l0', iteration_num, GANmodel.displayloss0.cpu().detach().numpy()) plotter.plot( 'l1', 'l1', 'l1', iteration_num, GANmodel.displayloss1.cpu().detach().numpy()) plotter.plot( 'l2', 'l2', 'l2', iteration_num, GANmodel.displayloss2.cpu().detach().numpy()) plotter.plot( 'l3', 'l3', 'l3', iteration_num, GANmodel.displayloss3.cpu().detach().numpy()) #plotter.plot( 'cLOSS1', 'cLOSS1', 'cLOSS1', iteration_num, D_x1.cpu().detach().numpy()) #plotter.plot( 'cLOSS12', 'cLOSS2', 'cLOSS2', iteration_num, D_x2.cpu().detach().numpy()) #plotter.plot( 'cLOSS_f', 'cLOSSf', 'cLOSSf', iteration_num, D_xf.cpu().detach().numpy()) if read_id % 1 == 0 and Display_fig_flag== True: #vutils.save_image(real_cpu, # '%s/real_samples.png' % opt.outf, # normalize=True) #netG.eval() #fake = netG(fixed_noise) #cv2.imwrite(Save_pic_dir + str(i) +".jpg", mat)