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

Method test_handler

tests/utils/test_profiling.py:181–208  ·  view source on GitHub ↗

Test profiling Engine objects works if Ignite is present.

(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 6

WorkflowProfilerClass · 0.90
SupervisedTrainerClass · 0.90
ProfileHandlerClass · 0.90
get_resultsMethod · 0.80
attachMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected