Closed zhanwenchen closed 1 year ago
Due to the wrong indentation, all dataset statistics are returned prematurely when using graft. Therefore graft to this date has been all incorrect.
def get_VG_statistics(self, must_overlap=True): num_obj_classes = len(self.ind_to_classes) num_rel_classes = len(self.ind_to_predicates) fg_matrix = np.zeros((num_obj_classes, num_obj_classes, num_rel_classes), dtype=np.int64) bg_matrix = np.zeros((num_obj_classes, num_obj_classes), dtype=np.int64) gt_classes = self.gt_classes relationships = self.relationships use_graft = self.use_graft is True if use_graft: stats = [] get_groundtruth = self.get_groundtruth else: gt_boxes = self.gt_boxes for ex_ind in tqdm(range(len(self))): # NOTE: the gt_boxes are right. The images haven't been transformed yet. gt_classes = gt_classes[ex_ind] gt_relations = relationships[ex_ind] if use_graft: target = get_groundtruth(ex_ind, evaluation=True, flip_img=False) bbox = target.bbox.numpy() del target keep = (bbox[:, 3] > bbox[:, 1]) & (bbox[:, 2] > bbox[:, 0]) gt_boxes = bbox.astype(int) del bbox else: gt_boxes = gt_boxes[ex_ind].numpy() # For the foreground, we'll just look at everything o1o2_indices = gt_relations[:, :2] o1o2 = gt_classes[o1o2_indices] # Regardless # QUESTION: are indicies and o1o2 even? Yes. assert len(o1o2_indices) == len(o1o2) for idx, ((o1_idx, o2_idx), (o1, o2), gtr) in enumerate(zip(o1o2_indices, o1o2, gt_relations[:, 2])): fg_matrix[o1, o2, gtr] += 1 # Keep shouldn't affect simple stats if use_graft: if keep[o1_idx] and keep[o2_idx]: gt_box_o1 = gt_boxes[o1_idx] gt_box_o2 = gt_boxes[o2_idx] row = [ex_ind, o1_idx, o1] + list(gt_box_o1) + [o2_idx, o2] + list(gt_box_o2) + [idx, gtr] stats.append(row) # For the background, get all of the things that overlap. o1o2_total = gt_classes[np.array( box_filter(gt_boxes, must_overlap=must_overlap), dtype=int)] for (o1, o2) in o1o2_total: bg_matrix[o1, o2] += 1 if use_graft: return fg_matrix, bg_matrix, stats return fg_matrix, bg_matrix
Need to cancel and rerun everything +visual. Done.
Due to the wrong indentation, all dataset statistics are returned prematurely when using graft. Therefore graft to this date has been all incorrect.