def assign_interaction_pairs()

in phosa/global_opt.py [0:0]


    def assign_interaction_pairs(self, verts_person, verts_object):
        """
        Assigns pairs of people and objects that are interacting. Note that multiple
        people can be assigned to the same object, but one person cannot be assigned to
        multiple objects. (This formulation makes sense for objects like motorcycles
        and bicycles. Can be changed for handheld objects like bats or rackets).

        This is computed separately from the loss function because there are potential
        speed improvements to re-using stale interaction pairs across multiple
        iterations (although not currently being done).

        A person and an object are interacting if the 3D bounding boxes overlap:
            * Check if X-Y bounding boxes overlap by projecting to image plane (with
              some expansion defined by BBOX_EXPANSION), and
            * Check if Z overlaps by thresholding distance.

        Args:
            verts_person (N_p x V_p x 3).
            verts_object (N_o x V_o x 3).

        Returns:
            interaction_pairs: List[Tuple(person_index, object_index)]
        """
        with torch.no_grad():
            bboxes_object = [
                project_bbox(v, self.renderer, bbox_expansion=self.expansion)
                for v in verts_object
            ]
            bboxes_person = [
                project_bbox(v, self.renderer, self.labels_person, self.expansion)
                for v in verts_person
            ]
            num_people = len(bboxes_person)
            num_objects = len(bboxes_object)
            ious = np.zeros((num_people, num_objects))
            for part_person in self.interaction_map:
                for i_person in range(num_people):
                    for i_object in range(num_objects):
                        iou = compute_iou(
                            bbox1=bboxes_object[i_object],
                            bbox2=bboxes_person[i_person][part_person],
                        )
                        ious[i_person, i_object] += iou

            self.interaction_pairs = []
            for i_person in range(num_people):
                i_object = np.argmax(ious[i_person])
                if ious[i_person][i_object] == 0:
                    continue
                dist = compute_dist_z(verts_person[i_person], verts_object[i_object])
                if dist < self.thresh:
                    self.interaction_pairs.append((i_person, i_object))
            return self.interaction_pairs