コード例 #1
0
# Use writer to record
writer = SummaryWriter(os.path.join(summary_name, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))))

# Prepare dataset & dataloader
valset = CSL_Isolated_Openpose2('trainvaltest')
val_loader = DataLoader(dataset=valset, batch_size = 8,
                        num_workers=8, pin_memory=True, shuffle=True)
valset2 = CSL_Isolated_Openpose2('trainval')
val_loader2 = DataLoader(dataset=valset2, batch_size = 8,
                        num_workers=8, pin_memory=True, shuffle=True)
valset3 = CSL_Isolated_Openpose2('test')
val_loader3 = DataLoader(dataset=valset3, batch_size = 8,
                        num_workers=8, pin_memory=True, shuffle=True)

model_cnn = gcrHCN(f_dim=args.feature_dim).to(device)
# model_gen = Hallucinator(args.feature_dim).to(device)
model = GCR_ri(model_cnn,train_way=args.train_way,\
    test_way=args.test_way, shot=args.shot,query=args.query,query_val=args.query_val,f_dim=args.feature_dim).to(device)
# Resume model
if checkpoint is not None:
    start_epoch, best_acc = resume_gcr_model(model, checkpoint, args.n_base)

# Create loss criterion
criterion = nn.CrossEntropyLoss()

# Start Test
print("Test Started".center(60, '#'))
for epoch in range(start_epoch, start_epoch+1):
    acc = evaluate_confusion_matrix(model,criterion,val_loader3,device,epoch,log_interval,writer,args,model.relation1,
                name='cmat/'+ store_name+'_cmat.csv')
コード例 #2
0
# Prepare dataset & dataloader
trainset = CSL_Isolated_Openpose('trainvaltest')
train_sampler = TsneSampler(trainset.label,
                            batch_size,
                            select_class=n_class,
                            n_sample=n_sample)
train_loader = DataLoader(dataset=trainset,
                          batch_sampler=train_sampler,
                          num_workers=num_workers,
                          pin_memory=True)
print('Len of the train loader: %d' % (len(train_loader)))
if model_name == 'HCN':
    model = hcn(args.num_class).to(device)
    start_epoch, best_acc = resume_model(model, checkpoint)
elif model_name == 'PN':
    model_cnn = gcrHCN().to(device)
    model = PN(model_cnn,lstm_input_size=args.feature_dim,train_way=args.train_way,test_way=args.test_way,\
        shot=args.shot,query=args.query,query_val=args.query_val).to(device)
    start_epoch, best_acc = resume_model(model, checkpoint)
elif model_name == 'RN':
    model_cnn = gcrHCN().to(device)
    model = RN(model_cnn,lstm_input_size=args.feature_dim,train_way=args.train_way,test_way=args.test_way,\
        shot=args.shot,query=args.query,query_val=args.query_val).to(device)
    start_epoch, best_acc = resume_model(model, checkpoint)
elif model_name == 'MN':
    model_cnn = gcrHCN().to(device)
    model = MN(model_cnn,lstm_input_size=args.feature_dim,train_way=args.train_way,test_way=args.test_way,\
        shot=args.shot,query=args.query,query_val=args.query_val).to(device)
    start_epoch, best_acc = resume_model(model, checkpoint)
elif model_name == 'GCR_ri':
    model_cnn = gcrHCN().to(device)