model_path = "./checkpoint"

start_epoch = 0
best_acc = 0.00
# Use specific gpus
os.environ["CUDA_VISIBLE_DEVICES"]=device_list
# Device setting
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# 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
train_loader, val_loader = getDataloader(dataset,args)

model_cnn = gcrHCN(f_dim=args.feature_dim).to(device)
# model = GCR_ni(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 cnn_ckpt is not None:
    resume_cnn_part(model_cnn,cnn_ckpt)
    # resume_cnn_part_with_fc7(model_cnn,cnn_ckpt)
if gcrr_ckpt is not None:
    resume_gcr_part(model, gcrr_ckpt, args.n_base)
if checkpoint is not None:
    start_epoch, best_acc = resume_gcr_model(model, checkpoint, args.n_base)
global_base, global_novel = load_global_proto(global_ckpt,args)

model = GCR_ni(model_cnn,global_base=global_base,global_novel=global_novel,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)
Exemple #2
0
best_acc = 0.00
# Use specific gpus
os.environ["CUDA_VISIBLE_DEVICES"] = device_list
# Device setting
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# 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
val_loader = getValloader(dataset, args)

model_cnn = gcrHCN().to(device)
model = GCR_i(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 & optimizer
criterion = loss_for_gcr_relation()

print(f"Evalation setting: {args.test_way} way {args.shot} shot")
# Start Evaluation
print("Evaluation Started".center(60, '#'))
for epoch in range(start_epoch, start_epoch + 1):
    # Eval the model
    acc, _ = eval_gcr_relation(model, criterion, val_loader, device, epoch,