Exemplo n.º 1
0
from trainers.eval import meta_test

with open('../../../../config.yml', 'r') as f:
    temp = yaml.safe_load(f)
data_path = os.path.abspath(temp['data_path'])

test_path = os.path.join(data_path, 'Aircraft_fewshot/test_pre')
model_path = './model_ResNet-12.pth'
#model_path = '../../../../trained_model_weights/Aircraft_fewshot/Proto/ResNet-12_5-shot/model.pth'

gpu = 0
torch.cuda.set_device(gpu)

model = Proto(resnet=True)
model.cuda()
model.load_state_dict(torch.load(model_path,
                                 map_location=util.get_device_map(gpu)),
                      strict=True)
model.eval()

with torch.no_grad():
    way = 5
    for shot in [5]:
        mean, interval = meta_test(data_path=test_path,
                                   model=model,
                                   way=way,
                                   shot=shot,
                                   pre=True,
                                   transform_type=None,
                                   trial=10000)
        print('%d-way-%d-shot acc: %.3f\t%.3f' % (way, shot, mean, interval))
Exemplo n.º 2
0
fewshot_path = os.path.join(data_path, 'tiered-ImageNet_DeepEMD')

pm = trainer.Path_Manager(fewshot_path=fewshot_path, args=args)

train_way = args.train_way
shots = [args.train_shot, args.train_query_shot]

train_loader = dataloaders.meta_train_dataloader(
    data_path=pm.train,
    way=train_way,
    shots=shots,
    transform_type=args.train_transform_type)

model = FRN(way=train_way,
            shots=[args.train_shot, args.train_query_shot],
            resnet=args.resnet)

pretrained_model_path = '../ResNet-12_pretrain/model_ResNet-12.pth'
#pretrained_model_path = '../../../../trained_model_weights/tiered-ImageNet_DeepEMD/FRN/ResNet-12_pretrain/model.pth'

model.load_state_dict(torch.load(pretrained_model_path,
                                 map_location=util.get_device_map(args.gpu)),
                      strict=False)

train_func = partial(frn_train.default_train, train_loader=train_loader)

tm = trainer.Train_Manager(args, path_manager=pm, train_func=train_func)

tm.train(model)

tm.evaluate(model)
Exemplo n.º 3
0
from models.Proto import Proto
from utils import util
from trainers.eval import meta_test


with open('../../../../config.yml', 'r') as f:
    temp = yaml.safe_load(f)
data_path = os.path.abspath(temp['data_path'])

test_path = os.path.join(data_path,'tiered_meta_iNat/test')
model_path = './model_Conv-4.pth'

gpu = 0
torch.cuda.set_device(gpu)

model = Proto(resnet=False)
model.cuda()
model.load_state_dict(torch.load(model_path,map_location=util.get_device_map(gpu)),strict=True)
model.eval()

with torch.no_grad():
    way = 5
    for shot in [1]:
        mean,interval = meta_test(data_path=test_path,
                                model=model,
                                way=way,
                                shot=shot,
                                pre=True,
                                transform_type=None,
                                trial=10000)
        print('%d-way-%d-shot acc: %.3f\t%.3f'%(way,shot,mean,interval))
Exemplo n.º 4
0
with open('../../../../config.yml', 'r') as f:
    temp = yaml.safe_load(f)
data_path = os.path.abspath(temp['data_path'])
fewshot_path = os.path.join(data_path,'mini-ImageNet')

pm = trainer.Path_Manager(fewshot_path=fewshot_path,args=args)

train_way = args.train_way
shots = [args.train_shot, args.train_query_shot]

train_loader = dataloaders.meta_train_dataloader(data_path=pm.train,
                                                way=train_way,
                                                shots=shots,
                                                transform_type=args.train_transform_type)

model = FRN(way=train_way,
            shots=[args.train_shot, args.train_query_shot],
            resnet=args.resnet)

pretrained_model_path = '../ResNet-12_pretrain/model_ResNet-12.pth'
#pretrained_model_path = '../../../../trained_model_weights/mini-ImageNet/FRN/ResNet-12_pretrain/model.pth'

model.load_state_dict(torch.load(pretrained_model_path,map_location=util.get_device_map(args.gpu)),strict=False)

train_func = partial(frn_train.default_train,train_loader=train_loader)

tm = trainer.Train_Manager(args,path_manager=pm,train_func=train_func)

tm.train(model)

tm.evaluate(model)