Integrate with Catalyst¶
Comet integrates with Catalyst.
Catalyst is a PyTorch framework for deep learning R&D. It focuses on reproducibility, rapid experimentation, and codebase reusability so you can create something new rather than write yet another train loop. The Catalyst library incorporates research best practices so users can focus on building models and not worry about writing boilerplate code.
import comet_ml
from catalyst import dl
logger = dl.CometLogger()
# Your training code goes here
Log automatically¶
Catalyst ships with a dedicated CometLogger
that is capable of logging the following data from your Catalyst runs.
- Metrics
- Hyperparameters
Configure the CometLogger for Catalyst¶
Find more information about the CometLogger
in the Catalyst documentation
End-to-end example¶
import comet_ml
import os
import torch
from torch import nn, optim
from torch.utils.data import DataLoader
from catalyst import dl, utils
from catalyst.data import ToTensor
from catalyst.contrib.datasets import MNIST
from torch.utils.data import DataLoader, TensorDataset
from catalyst import dl
from catalyst.callbacks.checkpoint import CheckpointCallback
logger = dl.CometLogger()
hparams={'lr': 0.02, 'batch_size':32}
model = nn.Sequential(nn.Flatten(), nn.Linear(28 * 28, 10))
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=hparams['lr'])
loaders = {
"train": DataLoader(
MNIST(os.getcwd(), train=True, download=True, transform=ToTensor()),
batch_size=hparams['batch_size'],
),
"valid": DataLoader(
MNIST(os.getcwd(), train=False, download=True, transform=ToTensor()),
batch_size=hparams['batch_size'],
),
}
runner = dl.SupervisedRunner(
input_key="features", output_key="logits", target_key="targets", loss_key="loss"
)
# model training
runner.train(
model=model,
criterion=criterion,
optimizer=optimizer,
loaders=loaders,
hparams=hparams,
num_epochs=1,
callbacks=[
dl.AccuracyCallback(
input_key="logits", target_key="targets", topk_args=(1, 3, 5)
),
dl.PrecisionRecallF1SupportCallback(
input_key="logits", target_key="targets", num_classes=10
),
],
logdir="./logs",
valid_loader="valid",
valid_metric="loss",
minimize_valid_metric=True,
verbose=True,
load_best_on_end=True,
loggers={"comet": logger},
)
Try it out!¶
Here's an example for using Comet with Catalyst.
Nov. 18, 2024