예제 #1
0
    def predict_behavior(self, image, bboxes, crop_height=112, crop_width=112):
        width, height = image.size
        boxes_data = []
        for bbox in bboxes:
            x1, y1, x2, y2 = bbox[:4]
            boxes_data.append(
                [y1 / height, x1 / width, y2 / height, x2 / width])

        image = np.array(image, dtype=np.float32)
        image = torch.from_numpy(image.transpose((2, 0, 1)))
        image_data = image.unsqueeze(0)
        image_data = torch.FloatTensor(image_data)

        boxes_data = torch.FloatTensor(boxes_data)
        boxes_index_data = torch.IntTensor([0 for _ in range(len(bboxes))])

        image_torch = to_varabile(image_data)  # N * C * H * W
        boxes = to_varabile(boxes_data)
        box_index = to_varabile(boxes_index_data)

        crops_torch = CropAndResizeFunction(crop_height, crop_width,
                                            0)(image_torch, boxes, box_index)
        crops_torch = crops_torch.sub_(self.mean).div_(self.std)

        outputs = self.model(crops_torch)
        score = self.softmax(outputs)

        pred = score.cpu().data.numpy()
        return pred
예제 #2
0
    def predict_behavior(self,
                         image_torch,
                         boxes,
                         box_index,
                         crop_height=112,
                         crop_width=112):
        """
        predict batch images
        """
        crops_torch = CropAndResizeFunction(crop_height, crop_width,
                                            0)(image_torch, boxes, box_index)
        crops_torch = crops_torch.sub_(self.mean).div_(self.std)

        outputs = self.model(crops_torch)
        score = self.softmax(outputs)
        pred = score.cpu().data.numpy()
        return pred