示例#1
0
 def __call__(self, gt_boxes, gt_labels):
     if type(gt_boxes) is np.ndarray:
         gt_boxes = torch.from_numpy(gt_boxes)
     if type(gt_labels) is np.ndarray:
         gt_labels = torch.from_numpy(gt_labels)
     boxes, labels = box_utils.assign_priors(gt_boxes, gt_labels,
                                             self.corner_form_priors, self.iou_threshold)
     boxes = box_utils.corner_form_to_center_form(boxes)
     locations = box_utils.convert_boxes_to_locations(boxes, self.center_form_priors, self.center_variance, self.size_variance)
     return locations, labels
示例#2
0
    def __call__(self, gt_boxes, gt_labels):
        if type(gt_boxes) is np.ndarray:
            gt_boxes = torch.from_numpy(gt_boxes)
        if type(gt_labels) is np.ndarray:
            gt_labels = torch.from_numpy(gt_labels)

        if (gt_boxes.shape[0] == 0):
            raise ValueError("Error in ground truth box size: " +
                             str(gt_boxes.shape))

        boxes, labels = box_utils.assign_priors(gt_boxes, gt_labels,
                                                self.corner_form_priors,
                                                self.iou_threshold)
        boxes = box_utils.corner_form_to_center_form(boxes)
        locations = box_utils.convert_boxes_to_locations(
            boxes, self.center_form_priors, self.center_variance,
            self.size_variance)
        return locations, labels
示例#3
0
    def __call__(self, quad_gt,img_prior=None):

        #将np array转为torch tensor
        # if type(quad) is np.ndarray:
        #     quad = torch.from_numpy(quad)
        priors_boxes,prior_boxed_labels = box_utils.assign_priors(quad_gt,self.quad_form_priors, self.iou_threshold,self.distance_threshold)

        # print('prior_boxed_labels:',prior_boxed_labels)
        true_default_box_index=np.where(prior_boxed_labels==1)
        true_default_box=self.quad_form_priors[true_default_box_index] * 512
        # print('self.quad_form_prior.shape:',np.shape(self.quad_form_priors))
        tmp = self.quad_form_priors[382200:382270,:] * 512
        # print('tmp.shape:',np.shape(tmp))
        # print('true_default_box.shape:',np.shape(true_default_box))
        if img_prior is not None:
            for i in range(np.shape(true_default_box)[0]):
                print(true_default_box[i])
                # print(quad[i])
                cv2.line(img_prior, (true_default_box[i][0], true_default_box[i][1]), (true_default_box[i][2], true_default_box[i][3]), (255, 0, 0), thickness=2)
                cv2.line(img_prior, (true_default_box[i][2], true_default_box[i][3]), (true_default_box[i][4], true_default_box[i][5]), (255, 0, 0), thickness=2)
                cv2.line(img_prior, (true_default_box[i][4], true_default_box[i][5]), (true_default_box[i][6], true_default_box[i][7]), (255, 0, 0), thickness=2)
                cv2.line(img_prior, (true_default_box[i][6], true_default_box[i][7]), (true_default_box[i][0], true_default_box[i][1]), (255, 0, 0), thickness=2)
            for i in range(np.shape(tmp)[0]):
                # print('tmp[i]',tmp[i])
                # print('i:',i)
                cv2.line(img_prior, (tmp[i][0], tmp[i][1]), (tmp[i][2], tmp[i][3]), (0, 0, 255), thickness=2)
                cv2.line(img_prior, (tmp[i][2], tmp[i][3]), (tmp[i][4], tmp[i][5]), (0, 0, 255), thickness=2)
                cv2.line(img_prior, (tmp[i][4], tmp[i][5]), (tmp[i][6], tmp[i][7]), (0, 0, 255), thickness=2)
                cv2.line(img_prior, (tmp[i][6], tmp[i][7]), (tmp[i][0], tmp[i][1]), (0, 0, 255), thickness=2)
            cv2.imshow('img_prior', img_prior)
            cv2.imwrite('test.jpg',img_prior)
            cv2.waitKey()
        # print('priors_boxes.shape',np.shape(priors_boxes))
        locations = box_utils.convert_boxes_to_locations(priors_boxes, self.quad_form_priors, self.center_variance, self.size_variance)
        #locations.size():[24564,8]
        #prior_boxed_labels.size():[24564,]
        return locations,prior_boxed_labels