(self)
| 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 | |
| 113 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected