PyTorch Ignite integration API reference

API reference for the NeptuneLogger class of the Neptune-Ignite integration.

TheNeptuneLoggerclass provided by the PyTorch Ignite library captures metadata that is generated when training and validating models with Ignite.

NeptuneLogger

Creates a Neptune handler to log metrics, model and optimizer parameters, and gradients during the training and validation. It can also log model checkpoints to Neptune.

Parameters

Name Type Default Description
api_token str, optional None User's Neptune API token. If None, the value of theNEPTUNE_API_TOKENenvironment variable is used.To keep your token secure, avoid placing it in the source code. Instead,save it as an environment variable.
project str, optional None Name of a project in the formworkspace-name/project-name. If None, the value of theNEPTUNE_PROJECTenvironment variable is used.
**neptune_run_kwargs str, optional - Additional keyword arguments to be passed directly to theinit_run()function, such asdescriptionandtags.

To keep your token secure, avoid placing it in the source code. Instead,save it as an environment variable.

Examples

If you have yourNeptune credentials saved as environment variables, the following starts the Neptune logger with default settings:

from ignite.contrib.handlers.neptune_logger import *

neptune_logger = NeptuneLogger()

neptune_logger.attach_output_handler(
 trainer,
 ...,
)

trainer.run()

You can also pass more options to the run created by the logger:

neptune_logger = NeptuneLogger(
 project="workspace-name/project-name", # (1)!
 name="My first Ignite run",
 description="Quick training run with Ignite",
 tags=["training", "low LR"],
)
  1. The full project name. For example,"ml-team/classification".
  2. You can copy the name from the project details ( → Details & privacy )
  3. You can also find a pre-filled project string in Experiments → Create a new run .

The full project name. For example,"ml-team/classification".

To log metadata to the Neptune run, access theneptune_logger.experimentattribute. You can then use any logging methods from the Neptune client library to track your metadata, such asappend(),assign()(=), andupload().

metadata = ...
neptune_logger.experiment["your/metadata/structure"] = metadata
...
neptune_logger.close()

NeptuneSaver

Handler that saves an input checkpoint to the Neptune server.

Windows note

NeptuneSaveris not supported on Windows.

Parameters

Name Type Default Description
neptune_logger NeptuneLogger - An instance of theNeptuneLoggerclass.

Example

Set up the logger:

from ignite.contrib.handlers.neptune_logger import *

neptune_logger = NeptuneLogger()
...
evaluator = create_supervised_evaluator(model, metrics=metrics, ...)
...

def score_function(engine):
 return engine.state.metrics["accuracy"]

to_save = {"model": model}

Pass the Neptune logger to the saver:

from ignite.handlers import Checkpoint

handler = Checkpoint(
 to_save,
 NeptuneSaver(neptune_logger), n_saved=2,
 filename_prefix="best", score_function=score_function,
 score_name="validation_accuracy",
 global_step_transform=global_step_from_engine(trainer),
)
evaluator.add_event_handler(Events.COMPLETED, handler)

Close the logger when done:

neptune_logger.close()

You can access example checkpoints and download them fromthis example run.

See also

NeptuneLoggerreference inIgnite API docs


This page is originally sourced from the legacy docs.