Beispiel #1
0
    def test_from_to_instances(self):
        orig = Instances((30, 30))
        orig.proposal_boxes = Boxes(torch.rand(3, 4))

        fields = {"proposal_boxes": Boxes, "a": Tensor}
        with patch_instances(fields) as NewInstances:
            # convert to NewInstances and back
            new1 = NewInstances.from_instances(orig)
            new2 = convert_scripted_instances(new1)
        self.assertTrue(torch.equal(orig.proposal_boxes.tensor, new1.proposal_boxes.tensor))
        self.assertTrue(torch.equal(orig.proposal_boxes.tensor, new2.proposal_boxes.tensor))
Beispiel #2
0
    def _test_retinanet_model(self, config_path):
        model = model_zoo.get(config_path, trained=True)
        model.eval()

        fields = {
            "pred_boxes": Boxes,
            "scores": Tensor,
            "pred_classes": Tensor,
        }
        script_model = export_torchscript_with_instances(model, fields)

        img = get_sample_coco_image()
        inputs = [{"image": img}]
        with torch.no_grad():
            instance = model(inputs)[0]["instances"]
            scripted_instance = convert_scripted_instances(script_model(inputs)[0])
            scripted_instance = detector_postprocess(scripted_instance, img.shape[1], img.shape[2])
        assert_instances_allclose(instance, scripted_instance)