Detectron2 integration API reference

API reference for the Neptune-Detectron2 integration.

You can use a Neptune hook to capture model training metadata during training and validation of detectron2 models.

NeptuneHook

Captures model training metadata and logs them to Neptune.

Parameters

Name Type Default Description
run RunorHandler - (required) An existing run reference, as returned byneptune.init_run(), or anamespace handler.
base_namespace str, optional "training" Namespace under which all metadata logged by the Neptune hook will be stored.
metrics_update_freq int, optional 20 How often NeptuneHook should log metrics (every nth iteration). The value must be greater than zero.Example: Setting it to10will log metrics every 10th iteration.Also applies to checkpoints, iflog_checkpointsis set toTrue
log_model bool, optional False Whether to upload the final model checkpoint, whenever it is saved by the Trainer. ExpectsCheckpointHookto be present.
log_checkpoints bool, optional False Whether to upload checkpoints whenever they are saved by the Trainer. ExpectsCheckpointHookto be present.

Example: Setting it to10will log metrics every 10th iteration.

Also applies to checkpoints, iflog_checkpointsis set toTrue

Examples

Creating a hook that sends the logs to an existing Neptune run object

import neptune

neptune_run = neptune.init_run()

neptune_hook = NeptuneHook(run=neptune_run)

As a best practice, you should save your Neptune API token and project name as environment variables:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

Alternatively, you can pass the information when using a function that takesapi_tokenandprojectas arguments:

run = neptune.init_run(
 api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)!
 project="ml-team/classification", # (2)!
)
  1. In the bottom-left corner, expand the user menu and select Get my API token .
  2. You can copy the path from the project details ( → Details & privacy ).

If you haven't registered, you can log anonymously to a public project:

api_token=neptune.ANONYMOUS_API_TOKEN
project="common/quickstarts"

Make sure not to publish sensitive data through your code!

Creating a Neptune run and hook with more options

In the following example, we set the Trainer to save model checkpoints every 10th epoch. Neptune will upload those checkpoints and metrics at the same interval.

neptune_run = neptune.init_run(
 project="workspace-name/project-name", # (1)!
 name="My detectron2 run",
 tags = ["validation"],
 capture_stdout=False,
)

neptune_hook = NeptuneHook(
 run=neptune_run,
 log_checkpoints=True,
 metrics_update_freq=10,
)
  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".

Additionally, we pass an extra option not to capture the stdout during the run (capture_stdout=False). For all the keyword arguments you can use, seeneptune≫init_run().

Passing a handler to the hook

To log the metadata to a specific namespace of the run, you can create anamespace handlerobject and pass that to the hook.

import neptune

neptune_run = neptune.init_run()

handler = neptune_run["validation"]

neptune_hook = NeptuneHook(run=handler)

In this case, all the metadata will be logged under thevalidationnamespace (folder) inside the run.

See also

neptune-detectron2 repo onGitHub


This page is originally sourced from the legacy docs.