コード例 #1
0
test_loader = torch.utils.data.DataLoader(
    testset, batch_size=opt.testepisodeSize, shuffle=True, 
    num_workers=int(opt.workers), drop_last=True, pin_memory=True
    ) 
print(opt)
print(opt, file=F_txt)



# ========================================== Model config ===============================================
ngpu = int(opt.ngpu)
global best_prec1, episode_train_index, best_prec2
best_prec1 = 0
best_prec2 = 0
episode_train_index = 0
model = Net.define_Net(which_model=opt.basemodel, num_classes=opt.way_num, norm='batch', 
    init_type='normal', use_gpu=opt.cuda)
global temprature_inc_rate, temprature_init,temprature
temprature_init = 1  # init temprature as 1 increase every 50000 iter
temprature_inc_rate = 30000
temprature = 1
# define loss function (criterion) and optimizer
criterion = nn.CrossEntropyLoss().cuda()
optimizer = optim.Adam(model.parameters(), lr=opt.lr, betas=(opt.beta1, 0.9))


# optionally resume from a checkpoint
if opt.resume:
    if os.path.isfile(opt.resume):
        print("=> loading checkpoint '{}'".format(opt.resume))
        checkpoint = torch.load(opt.resume)
        episode_train_index = checkpoint['episode_train_index']+1
コード例 #2
0
ファイル: test.py プロジェクト: minkee77/PPSML
# save the opt and results to a txt file
txt_save_path = os.path.join(opt.outf, 'Test_resutls.txt')
F_txt = open(txt_save_path, 'a+')
print(opt)
print(opt, file=F_txt)



# ========================================== Model Config ===============================================
ngpu = int(opt.ngpu)
global best_prec1, epoch_index
best_prec1 = 0
epoch_index = 0

model = Net.define_Net(which_model=opt.basemodel, metric=opt.metric, num_classes=opt.way_num, neighbor_k=opt.neighbor_k, norm='batch', 
	init_type='normal', use_gpu=opt.cuda, semi_neighbor_k=opt.semi_neighbor_k)

# define loss function (criterion) and optimizer
criterion = nn.CrossEntropyLoss().cuda()
optimizer = optim.Adam(model.parameters(), lr=opt.lr, betas=(opt.beta1, 0.9))


# optionally resume from a checkpoint
if opt.resume:
	if os.path.isfile(opt.resume):
		print("=> loading checkpoint '{}'".format(opt.resume))
		checkpoint = torch.load(opt.resume)
		epoch_index = checkpoint['epoch_index']
		best_prec1 = checkpoint['best_prec1']
		model.load_state_dict(checkpoint['state_dict'])
		optimizer.load_state_dict(checkpoint['optimizer'])