text stringlengths 1 93.6k |
|---|
optimizerD = optim.Adam(netD.parameters(),lr=1e-3)
|
criterion_bce=nn.BCELoss()
|
criterion_bce.cuda()
|
#net=UNet()
|
if opt.whichNet==1:
|
net = UNet(in_channel=opt.numOfChannel_allSource, n_classes=1)
|
elif opt.whichNet==2:
|
net = ResUNet(in_channel=opt.numOfChannel_allSource, n_classes=1)
|
elif opt.whichNet==3:
|
net = UNet_LRes(in_channel=opt.numOfChannel_allSource, n_classes=1)
|
elif opt.whichNet==4:
|
net = ResUNet_LRes(in_channel=opt.numOfChannel_allSource, n_classes=1, dp_prob = opt.dropout_rate)
|
#net.apply(weights_init)
|
net.cuda()
|
params = list(net.parameters())
|
print('len of params is ')
|
print(len(params))
|
print('size of params is ')
|
print(params[0].size())
|
optimizer = optim.Adam(net.parameters(),lr=opt.lr)
|
criterion_L2 = nn.MSELoss()
|
criterion_L1 = nn.L1Loss()
|
criterion_RTL1 = RelativeThreshold_RegLoss(opt.RT_th)
|
#criterion = nn.CrossEntropyLoss()
|
# criterion = nn.NLLLoss2d()
|
given_weight = torch.cuda.FloatTensor([1,4,4,2])
|
criterion_3d = CrossEntropy3d(weight=given_weight)
|
criterion_3d = criterion_3d.cuda()
|
criterion_L2 = criterion_L2.cuda()
|
criterion_L1 = criterion_L1.cuda()
|
criterion_RTL1 = criterion_RTL1.cuda()
|
#inputs=Variable(torch.randn(1000,1,32,32)) #here should be tensor instead of variable
|
#targets=Variable(torch.randn(1000,10,1,1)) #here should be tensor instead of variable
|
# trainset=data_utils.TensorDataset(inputs, targets)
|
# trainloader = data_utils.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)
|
# inputs=torch.randn(1000,1,32,32)
|
# targets=torch.LongTensor(1000)
|
path_test ='/home/niedong/DataCT/data_niigz/'
|
path_patients_h5 = '/home/niedong/DataCT/h5Data3D_noNorm/trainBatch3D_H5'
|
path_patients_h5_test ='/home/niedong/DataCT/h5Data3D_noNorm/val3D_H5'
|
# path_patients_h5_test ='/home/niedong/Data4LowDosePET/test2D_H5'
|
# batch_size=10
|
#data_generator = Generator_2D_slices(path_patients_h5,opt.batchSize,inputKey='data3T',outputKey='data7T')
|
#data_generator_test = Generator_2D_slices(path_patients_h5_test,opt.batchSize,inputKey='data3T',outputKey='data7T')
|
data_generator = Generator_3D_patches(path_patients_h5,opt.batchSize, inputKey='dataLPET', outputKey='dataHPET')
|
data_generator_test = Generator_3D_patches(path_patients_h5_test,opt.batchSize, inputKey='dataLPET', outputKey='dataHPET')
|
if opt.resume:
|
if os.path.isfile(opt.resume):
|
print("=> loading checkpoint '{}'".format(opt.resume))
|
checkpoint = torch.load(opt.resume)
|
net.load_state_dict(checkpoint['model'])
|
opt.start_epoch = 100000
|
opt.start_epoch = checkpoint["epoch"] - 1
|
# net.load_state_dict(checkpoint["model"].state_dict())
|
else:
|
print("=> no checkpoint found at '{}'".format(opt.resume))
|
########### We'd better use dataloader to load a lot of data,and we also should train several epoches###############
|
########### We'd better use dataloader to load a lot of data,and we also should train several epoches###############
|
running_loss = 0.0
|
start = time.time()
|
for iter in range(opt.start_epoch, opt.numofIters+1):
|
#print('iter %d'%iter)
|
# inputs, exinputs, labels = data_generator.next()
|
inputs, labels = data_generator.next()
|
# xx = np.transpose(inputs,(5,64,64))
|
# print 'size of inputs: ', inputs.shape
|
inputs = np.transpose(inputs,(0,4,1,2,3))
|
# inputs = np.squeeze(inputs) #16x64x64
|
# exinputs = np.squeeze(exinputs) #5x64x64
|
# print 'shape is ....',inputs.shape
|
labels = np.squeeze(labels) #64x64
|
# labels = labels.astype(int)
|
inputs = inputs.astype(float)
|
inputs = torch.from_numpy(inputs)
|
inputs = inputs.float()
|
# exinputs = exinputs.astype(float)
|
# exinputs = torch.from_numpy(exinputs)
|
# exinputs = exinputs.float()
|
labels = labels.astype(float)
|
labels = torch.from_numpy(labels)
|
labels = labels.float()
|
#print type(inputs), type(exinputs)
|
if opt.isMultiSource:
|
# source = torch.cat((inputs, exinputs),dim=1)
|
print 'you have to tune the multi source part'
|
else:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.