MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_plot

Method test_plot

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

Source from the content-addressed store, hash-verified

69 @SkipIfNoModule("ignite")
70 @SkipIfNoModule("matplotlib")
71 def test_plot(self):
72 set_determinism(0)
73 test_dir = Path(__file__).parents[1]
74 testing_dir = os.path.join(test_dir, "testing_data")
75
76 net = torch.nn.Conv2d(1, 1, 3, padding=1)
77
78 opt = torch.optim.Adam(net.parameters())
79
80 img = torch.rand(1, 16, 16)
81
82 # a third non-image key is added to test that this is correctly ignored when plotting
83 data = {CommonKeys.IMAGE: img, CommonKeys.LABEL: img, "Not Image Data": ["This isn't an image"]}
84
85 loader = DataLoader([data] * 20, batch_size=2)
86
87 trainer = SupervisedTrainer(
88 device=torch.device("cpu"),
89 max_epochs=1,
90 train_data_loader=loader,
91 network=net,
92 optimizer=opt,
93 loss_function=torch.nn.L1Loss(),
94 )
95
96 logger = MetricLogger()
97 logger.attach(trainer)
98
99 con = ThreadContainer(trainer)
100 con.start()
101 con.join()
102
103 fig = con.plot_status(logger)
104
105 with tempfile.TemporaryDirectory() as tempdir:
106 tempimg = f"{tempdir}/threadcontainer_plot_test.png"
107 fig.savefig(tempimg)
108 comp = compare_images(f"{testing_dir}/threadcontainer_plot_test.png", tempimg, 5e-2)
109
110 self.assertIsNone(comp, comp) # None indicates test passed
111
112
113if __name__ == "__main__":

Callers

nothing calls this directly

Calls 8

attachMethod · 0.95
plot_statusMethod · 0.95
set_determinismFunction · 0.90
DataLoaderClass · 0.90
SupervisedTrainerClass · 0.90
MetricLoggerClass · 0.90
ThreadContainerClass · 0.90
startMethod · 0.45

Tested by

no test coverage detected