def metric_eval(self, im, boxes, anchor_feature): box_regions = me_extract_regions(np.array(im), boxes) box_regions = process_regions(box_regions) box_regions = torch.Tensor(box_regions) box_regions = (Variable(box_regions)).type(torch.FloatTensor).cuda() box_features, class_result = self.metric_model(box_regions) class_result = torch.softmax(class_result, dim=1) ap_dist = torch.norm(anchor_feature - box_features, 2, dim=1).view(-1) return ap_dist
def metric_init(self, im, init_box): self.metric_model = ft_net(class_num=1120) path = os.path.join(base_path, 'utils/metric_net/metric_model/metric_model.pt') self.metric_model.eval() self.metric_model = self.metric_model.cuda() self.metric_model.load_state_dict(torch.load(path)) tmp = np.random.rand(1, 3, 107, 107) tmp = (Variable(torch.Tensor(tmp))).type(torch.FloatTensor).cuda() # get target feature self.metric_model(tmp) init_box = init_box.reshape((1, 4)) anchor_region = me_extract_regions(im, init_box) anchor_region = process_regions(anchor_region) anchor_region = torch.Tensor(anchor_region) anchor_region = (Variable(anchor_region)).type(torch.FloatTensor).cuda() self.anchor_feature, _ = self.metric_model(anchor_region)