MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / test_container

Method test_container

tests/data/test_threadcontainer.py:41–67  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

39class TestThreadContainer(unittest.TestCase):
40 @SkipIfNoModule("ignite")
41 def test_container(self):
42 net = torch.nn.Conv2d(1, 1, 3, padding=1)
43
44 opt = torch.optim.Adam(net.parameters())
45
46 img = torch.rand(1, 16, 16)
47 data = {CommonKeys.IMAGE: img, CommonKeys.LABEL: img}
48 loader = DataLoader([data for _ in range(10)])
49
50 trainer = SupervisedTrainer(
51 device=torch.device("cpu"),
52 max_epochs=1,
53 train_data_loader=loader,
54 network=net,
55 optimizer=opt,
56 loss_function=torch.nn.L1Loss(),
57 )
58
59 con = ThreadContainer(trainer)
60 con.start()
61 time.sleep(1) # wait for trainer to start
62
63 self.assertTrue(con.is_alive)
64 self.assertIsNotNone(con.status())
65 self.assertGreater(len(con.status_dict), 0)
66
67 con.join()
68
69 @SkipIfNoModule("ignite")
70 @SkipIfNoModule("matplotlib")

Callers

nothing calls this directly

Calls 5

statusMethod · 0.95
DataLoaderClass · 0.90
SupervisedTrainerClass · 0.90
ThreadContainerClass · 0.90
startMethod · 0.45

Tested by

no test coverage detected