def load_model(path, iscuda): checkpoint = common.load_checkpoint(path, iscuda) net = nets.create_model(pretrained="", **checkpoint['model_options']) net = common.switch_model_to_cuda(net, iscuda, checkpoint) net.load_state_dict(checkpoint['state_dict']) net.preprocess = checkpoint.get('preprocess', net.preprocess) if 'pca' in checkpoint: net.pca = checkpoint.get('pca') return net
def load_model(path=None, iscuda=''): checkpoint = common.load_checkpoint('./pretrained_model/Resnet50-AP-GeM.pt', iscuda) net = nets.create_model(pretrained="", **model_options)#**checkpoint['model_options'] net = common.switch_model_to_cuda(net, iscuda, checkpoint) if path: checkpoint_2 = common.load_checkpoint(path, iscuda) checkpoint_state_dict = checkpoint_2['state_dict'] start_epoch = checkpoint_2['epoch'] else: checkpoint_state_dict = checkpoint['state_dict'] start_epoch = 0 # net.load_state_dict(checkpoint_state_dict,False) load_param(net,checkpoint_state_dict) net.preprocess = checkpoint.get('preprocess', net.preprocess) if 'pca' in checkpoint: net.pca = checkpoint.get('pca') return net,start_epoch
def load_model(path, iscuda, whiten=None): checkpoint = common.load_checkpoint(path, iscuda) net = nets.create_model(pretrained="", **checkpoint['model_options']) net = common.switch_model_to_cuda(net, iscuda, checkpoint) net.load_state_dict(checkpoint['state_dict']) net.preprocess = checkpoint.get('preprocess', net.preprocess) if whiten is not None and 'pca' in checkpoint: if whiten in checkpoint['pca']: net.pca = checkpoint['pca'][whiten] return net
assert args.buffer_size % args.batch_size == 0 args.iscuda = common.torch_set_gpu(args.gpu) train_set = datasets.create('Landmarks_clean') val_set = datasets.create('RParis6K') model_options = { 'arch': args.arch, 'out_dim': args.out_dim, 'pooling': args.pooling, 'gemp': args.gemp } start_epoch = 0 if os.path.isfile(args.resume): checkpoint = common.load_checkpoint(args.resume, args.iscuda) net = nets.create_model(pretrained='', **model_options) net = common.switch_model_to_cuda(net, args.iscuda, checkpoint) net.load_state_dict(checkpoint['state_dict']) start_epoch = int( os.path.splitext(os.path.basename(args.resume))[0].split('_')[-1]) else: net = nets.create_model(pretrained='imagenet', **model_options) net = common.switch_model_to_cuda(net, iscuda=True) optimizer = torch.optim.Adam(net.parameters(), lr=args.lr, weight_decay=1e-6) criterion = APLoss(20, -1, 1) best_map = 0