What if I want to run my evaluation engine (which itself has event handlers) with my evaluation dataloader every 20 epochs of the training engine? Right now this isn’t possible, so I made a wrapper function that allows for this below. However, I was wondering if there was an ignite way of doing this? I couldn’t find any.
def _lf_two( log_fn: Callable[[Engine, List[str]], None], inner_engine: Engine, loader: DataLoader, **kwargs ) -> Callable[[Engine], Any]: """Returns a lambda calling custom log function with two engines (e.g. the training loop and validation loop)""" return lambda outer_engine: log_fn( inner_engine, loader, epoch_num=outer_engine.state.epoch, **kwargs ) def run_engine_and_log_output( engine: Engine, loader: DataLoader, fields: List[str], epoch_num=None, ) -> None: engine.run(loader,max_epochs=1, epoch_length=10) ###Here i grab things from engine.state.output and do what i want### trainer.add_event_handler( Events.EPOCH_COMPLETED(every=20), _lf_two( run_engine_and_log_output, evaluator, val_loader))
Also, I was wondering if I then wanted to run the evaluation outside of the training loop, and this time with different event handlers, would best practice be to create two different evaluation engines? One to pass into the training loop event handler into (__lf_two()), and one to run after my train.run ?