Skip to content

Start tracking a training run¶

Each training run is an Experiment in Comet. When you start an Experiment with Comet, you unlock the ability to interactively analyze the Experiment performance and manage its state over time.

Comet Single Experiment Page
The Comet Single Experiment page

Start tracking a training run¶

When you start an Experiment, Comet instantly begins tracking all attributes associated to the code execution at the url displayed after Experiment creation.

Before you start tracking your first traning run, we recommend calling the comet_ml.login() method. It will prompt you for your API key if it hasn't been saved already. You can learn about how to configure your API key in Configure the Comet SDK.

You can then start logging a training run using the comet_ml.start() method:

1
2
3
4
import comet_ml

comet_ml.login()
exp = comet_ml.start()
1
2
3
4
import comet_ml

comet_ml.login()
exp = comet_ml.start(experiment_key=PREVIOUS_EXPERIMENT_KEY)

Tip

The comet_ml.start method has an optional ExperimentConfig argument that can be used to set the name of the Experiment or configure the data that should be automatically logged. You can learn more about it in the SDK reference documentation.

Once an Experiment has been started, Comet will automatically start logging:

  • Metrics and hyper-parameters thanks to our many integrations.
  • The code file your Experiment was created in.
  • The git commit and git patch (uncommitted files) if you are running within a git repository.
  • Console output logs.
  • Installed python packages.
  • System metrics (Memory usage, GPU usage, etc).

Log metrics, parameters, and assets to your Experiment¶

In addition to all the data Comet logs for you, you can log any other types of data to the Comet platform using one of our logging methods.

In the example below we log a metric and an image:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import comet_ml
from PIL import Image
import requests

comet_ml.login()
exp = comet_ml.start()

# Log a metric
exp.log_metric('my_metric', 0.99)

# Log a parameter
exp.log_parameter('my_parameter', 0.001)

# Log an image
image_url = "https://cdn.pixabay.com/photo/2016/12/04/21/58/rabbit-1882699_1280.jpg"
response = requests.get(image_url)
pil_image = Image.open(io.BytesIO(response.content))

exp.log_image(image_data=pil_image, name="example_pil")

Comet automatically associates my_metric, my_parameter, and my_image.png to the Experiment represented by the exp object.

Nov. 18, 2024