(self)
| 15 | |
| 16 | class FastRCNNTest(unittest.TestCase): |
| 17 | def test_fast_rcnn(self): |
| 18 | torch.manual_seed(132) |
| 19 | |
| 20 | box_head_output_size = 8 |
| 21 | |
| 22 | box_predictor = FastRCNNOutputLayers( |
| 23 | ShapeSpec(channels=box_head_output_size), |
| 24 | box2box_transform=Box2BoxTransform(weights=(10, 10, 5, 5)), |
| 25 | num_classes=5, |
| 26 | ) |
| 27 | feature_pooled = torch.rand(2, box_head_output_size) |
| 28 | predictions = box_predictor(feature_pooled) |
| 29 | |
| 30 | proposal_boxes = torch.tensor([[0.8, 1.1, 3.2, 2.8], [2.3, 2.5, 7, 8]], dtype=torch.float32) |
| 31 | gt_boxes = torch.tensor([[1, 1, 3, 3], [2, 2, 6, 6]], dtype=torch.float32) |
| 32 | proposal = Instances((10, 10)) |
| 33 | proposal.proposal_boxes = Boxes(proposal_boxes) |
| 34 | proposal.gt_boxes = Boxes(gt_boxes) |
| 35 | proposal.gt_classes = torch.tensor([1, 2]) |
| 36 | |
| 37 | with EventStorage(): # capture events in a new storage to discard them |
| 38 | losses = box_predictor.losses(predictions, [proposal]) |
| 39 | |
| 40 | expected_losses = { |
| 41 | "loss_cls": torch.tensor(1.7951188087), |
| 42 | "loss_box_reg": torch.tensor(4.0357131958), |
| 43 | } |
| 44 | for name in expected_losses.keys(): |
| 45 | assert torch.allclose(losses[name], expected_losses[name]) |
| 46 | |
| 47 | def test_fast_rcnn_empty_batch(self, device="cpu"): |
| 48 | box_predictor = FastRCNNOutputLayers( |
nothing calls this directly
no test coverage detected