text stringlengths 1 93.6k |
|---|
#print('loss for generator is %f'%lossG.data[0])
|
#print statistics
|
running_loss = running_loss + lossG_G.data[0]
|
if iter%opt.showTrainLossEvery==0: #print every 2000 mini-batches
|
print '************************************************'
|
print 'time now is: ' + time.asctime(time.localtime(time.time()))
|
# print 'running loss is ',running_loss
|
print 'average running loss for generator between iter [%d, %d] is: %.5f'%(iter - 100 + 1,iter,running_loss/100)
|
print 'lossG_G is %.5f respectively.'%(lossG_G.data[0])
|
if opt.isAdLoss:
|
print 'loss_real is ',loss_real.data[0],'loss_fake is ',loss_fake.data[0],'outputD_real is',outputD_real.data[0]
|
print('loss for discriminator is %f'%lossD.data[0])
|
print 'cost time for iter [%d, %d] is %.2f'%(iter - 100 + 1,iter, time.time()-start)
|
print '************************************************'
|
running_loss = 0.0
|
start = time.time()
|
if iter%opt.saveModelEvery==0: #save the model
|
state = {
|
'epoch': iter+1,
|
'model': net.state_dict()
|
}
|
torch.save(state, opt.prefixModelName+'%d.pt'%iter)
|
print 'save model: '+opt.prefixModelName+'%d.pt'%iter
|
if opt.isAdLoss:
|
torch.save(netD.state_dict(), opt.prefixModelName+'_net_D%d.pt'%iter)
|
if iter%opt.decLREvery==0:
|
opt.lr = opt.lr*0.5
|
adjust_learning_rate(optimizer, opt.lr)
|
if iter%opt.showValPerformanceEvery==0: #test one subject
|
# to test on the validation dataset in the format of h5
|
# inputs,exinputs,labels = data_generator_test.next()
|
inputs, labels = data_generator_test.next()
|
inputs = np.transpose(inputs,(0,4,1,2,3))
|
# inputs = np.squeeze(inputs)
|
# exinputs = np.transpose(exinputs, (0, 3, 1, 2))
|
# exinputs = np.squeeze(exinputs) # 5x64x64
|
labels = np.squeeze(labels)
|
inputs = torch.from_numpy(inputs)
|
inputs = inputs.float()
|
# exinputs = torch.from_numpy(exinputs)
|
# exinputs = exinputs.float()
|
labels = torch.from_numpy(labels)
|
labels = labels.float()
|
# mid_slice = opt.numOfChannel_singleSource // 2
|
residual_source = inputs
|
if opt.isMultiSource:
|
# source = torch.cat((inputs, exinputs), dim=1)
|
print 'you have to tune the multi source part'
|
else:
|
source = inputs
|
source = source.cuda()
|
residual_source = residual_source.cuda()
|
labels = labels.cuda()
|
source,residual_source,labels = Variable(source),Variable(residual_source), Variable(labels)
|
# source = inputs
|
#outputG = net(inputs)
|
if opt.whichNet == 3 or opt.whichNet == 4:
|
outputG = net(source, residual_source) # 5x64x64->1*64x64
|
else:
|
outputG = net(source) # 5x64x64->1*64x64
|
#outputG = net(source,residual_source) #5x64x64->1*64x64
|
if opt.whichLoss == 1:
|
lossG_G = criterion_L1(torch.squeeze(outputG), torch.squeeze(labels))
|
elif opt.whichLoss == 2:
|
lossG_G = criterion_RTL1(torch.squeeze(outputG), torch.squeeze(labels))
|
else:
|
lossG_G = criterion_L2(torch.squeeze(outputG), torch.squeeze(labels))
|
lossG_G = opt.lossBase * lossG_G
|
print '.......come to validation stage: iter {}'.format(iter),'........'
|
print 'lossG_G is %.5f.'%(lossG_G.data[0])
|
if iter % opt.showTestPerformanceEvery == 0: # test one subject
|
mr_test_itk=sitk.ReadImage(os.path.join(path_test,'sub1_sourceCT.nii.gz'))
|
ct_test_itk=sitk.ReadImage(os.path.join(path_test,'sub1_extraCT.nii.gz'))
|
hpet_test_itk = sitk.ReadImage(os.path.join(path_test, 'sub1_targetCT.nii.gz'))
|
spacing = hpet_test_itk.GetSpacing()
|
origin = hpet_test_itk.GetOrigin()
|
direction = hpet_test_itk.GetDirection()
|
mrnp=sitk.GetArrayFromImage(mr_test_itk)
|
ctnp=sitk.GetArrayFromImage(ct_test_itk)
|
hpetnp=sitk.GetArrayFromImage(hpet_test_itk)
|
##### specific normalization #####
|
# mu = np.mean(mrnp)
|
# maxV, minV = np.percentile(mrnp, [99 ,25])
|
# #mrimg=mrimg
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.