MCPcopy
hub / github.com/hustvl/Vim / test_fast_rcnn_empty_batch

Method test_fast_rcnn_empty_batch

det/tests/modeling/test_fast_rcnn.py:47–64  ·  view source on GitHub ↗
(self, device="cpu")

Source from the content-addressed store, hash-verified

45 assert torch.allclose(losses[name], expected_losses[name])
46
47 def test_fast_rcnn_empty_batch(self, device="cpu"):
48 box_predictor = FastRCNNOutputLayers(
49 ShapeSpec(channels=10),
50 box2box_transform=Box2BoxTransform(weights=(10, 10, 5, 5)),
51 num_classes=8,
52 ).to(device=device)
53
54 logits = torch.randn(0, 100, requires_grad=True, device=device)
55 deltas = torch.randn(0, 4, requires_grad=True, device=device)
56 losses = box_predictor.losses([logits, deltas], [])
57 for value in losses.values():
58 self.assertTrue(torch.allclose(value, torch.zeros_like(value)))
59 sum(losses.values()).backward()
60 self.assertTrue(logits.grad is not None)
61 self.assertTrue(deltas.grad is not None)
62
63 predictions, _ = box_predictor.inference([logits, deltas], [])
64 self.assertEqual(len(predictions), 0)
65
66 @unittest.skipIf(not torch.cuda.is_available(), "CUDA not available")
67 def test_fast_rcnn_empty_batch_cuda(self):

Callers 1

Calls 7

ShapeSpecClass · 0.90
Box2BoxTransformClass · 0.90
toMethod · 0.45
lossesMethod · 0.45
backwardMethod · 0.45
inferenceMethod · 0.45

Tested by

no test coverage detected