Integrate with Fast.ai¶
fastai is a deep learning library which provides practitioners with high-level components that can quickly and easily provide state-of-the-art results in standard deep learning domains, and provides researchers with low-level components that can be mixed and matched to build new approaches.
Comet SDK | Minimum SDK version | Minimum fastai version |
---|---|---|
Python-SDK | 3.37.0 | 2.7.11 |
Start logging¶
Connect Comet to your existing code by adding in a simple Comet Experiment.
Add the following lines of code to your script or notebook:
import comet_ml
import fastai.vision
# Your code here
learn = fastai.vision.vision_learner(...)
Log automatically¶
By integrating with fastai, Comet automatically logs the following items:
- Model and graph description
- Training metrics
- Steps and epochs
- HyperParameters
End to End Example¶
If you can't wait, check out the results of this example fastai experiment for a preview of what's to come.
Install Dependencies¶
python -m pip install -U "comet_ml>=3.44.0" fastai
Run the example¶
import comet_ml
from fastai.vision.all import (
Categorize,
Datasets,
GrandparentSplitter,
IntToFloatTensor,
PILImageBW,
ToTensor,
URLs,
error_rate,
get_image_files,
parent_label,
resnet18,
untar_data,
vision_learner,
)
EPOCHS = 5
comet_ml.login()
experiment = comet_ml.start(project_name="comet-example-fastai-hello-world")
path = untar_data(URLs.MNIST_TINY)
items = get_image_files(path)
tds = Datasets(
items,
[PILImageBW.create, [parent_label, Categorize()]],
splits=GrandparentSplitter()(items),
)
dls = tds.dataloaders(after_item=[ToTensor(), IntToFloatTensor()])
learn = vision_learner(dls, resnet18, pretrained=True, metrics=error_rate)
learn.fit_one_cycle(EPOCHS)
experiment.end()
Try it out!¶
Don't just take our word for it, try it out for yourself.
- For more examples using fastai, see our examples GitHub repository.
- Run the end-to-end example above in Colab:
Use the Comet fastai callback¶
Comet logs your experiment through a callback executed when you run Learner.fit()
in fastai. You do not need to add this callback yourself, we do it for you automatically. However, if you ever need to access the callback manually, call experiment.get_callback("fastai")
.
Configure Comet for fastai¶
You can control which fastai items are logged automatically. Use any of the following methods:
experiment = comet_ml.start(
auto_metric_logging=True # Can be True or False
auto_param_logging=True # Can be True or False
)
Add or remove these fields from your .comet.config
file under the [comet_auto_log]
section to enable or disable logging.
[comet_auto_log]
metrics=true # can be true or false
parameters=true # can be true or false
export COMET_AUTO_LOG_PARAMETERS=true # Can be true or false
export COMET_AUTO_LOG_METRICS=true # Can be true or false
For more information about configuring Comet, see Configure Comet.