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

Class SupervisedEvaluator

monai/engines/evaluator.py:174–347  ·  view source on GitHub ↗

Standard supervised evaluation method with image and label(optional), inherits from evaluator and Workflow. Args: device: an object representing the device on which to run. val_data_loader: Ignite engine use data_loader to run, must be Iterable, typically be torch.DataLoade

Source from the content-addressed store, hash-verified

172
173
174class SupervisedEvaluator(Evaluator):
175 """
176 Standard supervised evaluation method with image and label(optional), inherits from evaluator and Workflow.
177
178 Args:
179 device: an object representing the device on which to run.
180 val_data_loader: Ignite engine use data_loader to run, must be Iterable, typically be torch.DataLoader.
181 network: network to evaluate in the evaluator, should be regular PyTorch `torch.nn.Module`.
182 epoch_length: number of iterations for one epoch, default to `len(val_data_loader)`.
183 non_blocking: if True and this copy is between CPU and GPU, the copy may occur asynchronously
184 with respect to the host. For other cases, this argument has no effect.
185 prepare_batch: function to parse expected data (usually `image`, `label` and other network args)
186 from `engine.state.batch` for every iteration, for more details please refer to:
187 https://pytorch.org/ignite/generated/ignite.engine.create_supervised_trainer.html.
188 iteration_update: the callable function for every iteration, expect to accept `engine`
189 and `engine.state.batch` as inputs, return data will be stored in `engine.state.output`.
190 if not provided, use `self._iteration()` instead. for more details please refer to:
191 https://pytorch.org/ignite/generated/ignite.engine.engine.Engine.html.
192 inferer: inference method that execute model forward on input data, like: SlidingWindow, etc.
193 postprocessing: execute additional transformation for the model output data.
194 Typically, several Tensor based transforms composed by `Compose`.
195 key_val_metric: compute metric when every iteration completed, and save average value to
196 engine.state.metrics when epoch completed. key_val_metric is the main metric to compare and save the
197 checkpoint into files.
198 additional_metrics: more Ignite metrics that also attach to Ignite Engine.
199 metric_cmp_fn: function to compare current key metric with previous best key metric value,
200 it must accept 2 args (current_metric, previous_best) and return a bool result: if `True`, will update
201 `best_metric` and `best_metric_epoch` with current metric and epoch, default to `greater than`.
202 val_handlers: every handler is a set of Ignite Event-Handlers, must have `attach` function, like:
203 CheckpointHandler, StatsHandler, etc.
204 amp: whether to enable auto-mixed-precision evaluation, default is False.
205 mode: model forward mode during evaluation, should be 'eval' or 'train',
206 which maps to `model.eval()` or `model.train()`, default to 'eval'.
207 event_names: additional custom ignite events that will register to the engine.
208 new events can be a list of str or `ignite.engine.events.EventEnum`.
209 event_to_attr: a dictionary to map an event to a state attribute, then add to `engine.state`.
210 for more details, check: https://pytorch.org/ignite/generated/ignite.engine.engine.Engine.html
211 #ignite.engine.engine.Engine.register_events.
212 decollate: whether to decollate the batch-first data to a list of data after model computation,
213 recommend `decollate=True` when `postprocessing` uses components from `monai.transforms`.
214 default to `True`.
215 to_kwargs: dict of other args for `prepare_batch` API when converting the input data, except for
216 `device`, `non_blocking`.
217 amp_kwargs: dict of the args for `torch.autocast("cuda")` API, for more details:
218 https://pytorch.org/docs/stable/amp.html#torch.autocast.
219 compile: whether to use `torch.compile`, default is False. If True, MetaTensor inputs will be converted to
220 `torch.Tensor` before forward pass, then converted back afterward with copied meta information.
221 compile_kwargs: dict of the args for `torch.compile()` API, for more details:
222 https://pytorch.org/docs/stable/generated/torch.compile.html#torch-compile.
223
224 """
225
226 def __init__(
227 self,
228 device: torch.device,
229 val_data_loader: Iterable | DataLoader,
230 network: torch.nn.Module,
231 epoch_length: int | None = None,

Callers 14

initializeMethod · 0.90
run_training_testFunction · 0.90
run_inference_testFunction · 0.90
test_contentMethod · 0.90
test_workflowMethod · 0.90
test_computeMethod · 0.90
test_computeMethod · 0.90
test_computeMethod · 0.90
test_contentMethod · 0.90
test_output_sizesMethod · 0.90
test_conditioningMethod · 0.90

Calls

no outgoing calls

Tested by 13

run_training_testFunction · 0.72
run_inference_testFunction · 0.72
test_contentMethod · 0.72
test_workflowMethod · 0.72
test_computeMethod · 0.72
test_computeMethod · 0.72
test_computeMethod · 0.72
test_contentMethod · 0.72
test_output_sizesMethod · 0.72
test_conditioningMethod · 0.72
test_computeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…