Test profiling Engine objects works if Ignite is present.
(self)
| 179 | |
| 180 | @SkipIfNoModule("ignite") |
| 181 | def test_handler(self): |
| 182 | """Test profiling Engine objects works if Ignite is present.""" |
| 183 | from ignite.engine import Events |
| 184 | |
| 185 | from monai.engines import SupervisedTrainer |
| 186 | |
| 187 | net = torch.nn.Conv2d(1, 1, 3, padding=1) |
| 188 | im = torch.rand(1, 1, 16, 16) |
| 189 | |
| 190 | with WorkflowProfiler(None) as wp: |
| 191 | trainer = SupervisedTrainer( |
| 192 | device=torch.device("cpu"), |
| 193 | max_epochs=2, |
| 194 | train_data_loader=[{CommonKeys.IMAGE: im, CommonKeys.LABEL: im}] * 3, |
| 195 | epoch_length=3, |
| 196 | network=net, |
| 197 | optimizer=torch.optim.Adam(net.parameters()), |
| 198 | loss_function=torch.nn.L1Loss(), |
| 199 | ) |
| 200 | |
| 201 | _ = ProfileHandler("Epoch", wp, Events.EPOCH_STARTED, Events.EPOCH_COMPLETED).attach(trainer) |
| 202 | |
| 203 | trainer.run() |
| 204 | |
| 205 | results = wp.get_results() |
| 206 | |
| 207 | self.assertSequenceEqual(set(results), {"Epoch"}) |
| 208 | self.assertEqual(len(results["Epoch"]), 2) |
nothing calls this directly
no test coverage detected