def load_model(opt, pretrained_path): seed = int(time.time()) use_cuda = True gpus = '0' torch.manual_seed(seed) if use_cuda: os.environ['CUDA_VISIBLE_DEVICES'] = gpus torch.cuda.manual_seed(seed) # Create model model = YOWO(opt) model = model.cuda() # model = nn.DataParallel(model, device_ids=None) # in multi-gpu case model.seen = 0 checkpoint = torch.load(pretrained_path) epoch = checkpoint['epoch'] fscore = checkpoint['fscore'] model.load_state_dict(checkpoint['state_dict'], strict=False) return model, epoch, fscore
use_cuda = True kwargs = {'num_workers': 0, 'pin_memory': True} if use_cuda else {} # Create model model = YOWO(opt) model = model.cuda() model = nn.DataParallel(model, device_ids=None) # in multi-gpu case print(model) # Load resume path if opt.resume_path: print("===================================================================") print('loading checkpoint {}'.format(opt.resume_path)) checkpoint = torch.load(opt.resume_path) model.load_state_dict(checkpoint['state_dict']) model.eval() print("===================================================================") def get_clip(root, imgpath, train_dur, dataset): im_split = imgpath.split('/') num_parts = len(im_split) class_name = im_split[-3] file_name = im_split[-2] im_ind = int(im_split[num_parts - 1][0:5]) if dataset == 'ucf101-24': img_name = os.path.join(class_name, file_name, '{:05d}.jpg'.format(im_ind)) elif dataset == 'jhmdb-21': img_name = os.path.join(class_name, file_name, '{:05d}.png'.format(im_ind))
if opt.resume_path: print( "===================================================================") print('loading checkpoint {}'.format(opt.resume_path)) checkpoint = torch.load(opt.resume_path) opt.begin_epoch = checkpoint['epoch'] best_fscore = checkpoint['fscore'] pretrained_dict = checkpoint['state_dict'] model_dict = model.state_dict() pretrained_dict = { k: v for k, v in pretrained_dict.items() if k in model_dict and k != 'module.cfam.conv_bn_relu1.0.weight' } model_dict.update(pretrained_dict) model.load_state_dict(model_dict) # model.load_state_dict(checkpoint['state_dict']) #optimizer.load_state_dict(checkpoint['optimizer']) model.seen = checkpoint['epoch'] * nsamples print("Loaded model fscore: ", checkpoint['fscore']) print( "===================================================================") region_loss.seen = model.seen processed_batches = model.seen // batch_size init_width = int(net_options['width']) init_height = int(net_options['height']) init_epoch = model.seen // nsamples