def extract_reid_features(reid_model, image, tlbrs): if len(tlbrs) == 0: return torch.FloatTensor() patches = extract_image_patches(image, tlbrs) patches = np.asarray( [im_preprocess(cv2.resize(p, reid_model.inp_size)) for p in patches], dtype=np.float32) gpu = net_utils.get_device(reid_model) with torch.no_grad(): im_var = Variable(torch.from_numpy(patches)) if gpu is not None: im_var = im_var.cuda(gpu) features = reid_model(im_var).data return features
def extract_reid_features(reid_model, image, tlbrs): if len(tlbrs) == 0: return torch.FloatTensor() patches = extract_image_patches(image, tlbrs) gpu = net_utils.get_device(reid_model) if LooseVersion(torch.__version__) > LooseVersion('0.3.1'): with torch.no_grad(): im_var = Variable(torch.from_numpy(patches)) if gpu is not None: im_var = im_var.cuda(gpu).float() features = reid_model(im_var).data else: im_var = Variable(torch.from_numpy(patches), volatile=True) if gpu is not None: im_var = im_var.cuda(gpu) features = reid_model(im_var).data return features
def appearance_features(appearance_model, image, tlbrs): if len(tlbrs) == 0: return torch.FloatTensor() candidates = extract_candidates(image, tlbrs) candidates = np.asarray( [im_preprocess(cv2.resize(c, (224, 224))) for c in candidates], dtype=np.float32) gpu = net_utils.get_device(appearance_model) if LooseVersion(torch.__version__) > LooseVersion('0.3.1'): with torch.no_grad(): im_var = Variable(torch.from_numpy(candidates)) if gpu is not None: im_var = im_var.cuda(gpu) features = appearance_model(im_var).data else: im_var = Variable(torch.from_numpy(candidates), volatile=True) if gpu is not None: im_var = im_var.cuda(gpu) features = appearance_model(im_var).data return features