Get slack notifications for FastAI model training.
fastai_slack provides a simple callback to receive Slack notifcations while training FastAI models, with just one extra line of code.
fastai_slack sends notifications to your chosen Slack workspace & channel for the following events:
fastai_slacklibrary using pip:
pip install fastai_slack
The webhook URL should be kept secret, so
fastai_slack provides a helpful
read_webhook_url method to safely input webhook URL within Jupyter.
from fastai_slack import read_webhook_url
webhook_url = read_webhook_url()
Enter webhook URL: ········
fastai_slack provides a callback called
SlackCallback which you can include within the
fit function call.
As an example, let's train a ResNet18 network on the MINST dataset.
from fastai.vision import *
We begin by downloading the data and creating an
path = untar_data(URLs.MNIST) data = ImageDataBunch.from_folder(path,train='training', valid='testing') data.show_batch(rows=3, figsize=(5,5))
/mnt/terabyte/miniconda3/envs/fastai-v1/lib/python3.7/site-packages/fastai/datasets.py:163: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. with open(fpath, 'r') as yaml_file: return yaml.load(yaml_file)
Next, we create the FastAI
Learner object, and call the
fit method to train the model, passing in a
SlackCallback configured with:
name: project/job name which will be included in every notification
webhook_url: The Slack incoming webhook URL (read from user input earlier)
frequency: How often to send a notification (defaults to 1 i.e. every epoch)
from fastai_slack import SlackCallback
# Create a learner learn = cnn_learner(data, models.resnet18, metrics=accuracy) # Create a callback slack_cb = SlackCallback('mnist', webhook_url, frequency=2) # fit with callback learn.fit(8, callbacks=[slack_cb])
Slack notification tag: [mnist 36qw8d]
This callback will send notifications every 2 epochs, and also notfiy you if there's an exception. Each
fit call is identified by a unique tag e.g.
[mnist-resnet18 xtfl18] that appears in every Slack message.
Here's what the notifications look like:
Instead of passing the webhook URL manually each time, you can also set a system wide environment variable with the name
FASTAI_SLACK_WEBHOOK contaning the URL, and it will be read automatically by
SlackCallback. For instance, on Mac/Linux, you might need to add the following like to your
FASTAI_SLACK_WEBHOOK=https://hooks.slack.com/services/T00000/B0000/XXXXXXXXXXX # Replace the URL above with your Slack incoming webhook URL
Here's an example where the webhook isn't specified manually:
You must provide a "Slack Incoming Webhook" URL for sending messages. You can generate a webhook URL for your workspace by following this guide: https://api.slack.com/incoming-webhooks Enter webhook URL: ········ Slack notification tag: [mnist oxvqc2]
fastai_slack is open source, and you can view the source code here: https://github.com/swiftace-ai/fastai_slack
Please use Github to report bugs, request/propose feature. Pull requests with bug fixes and PRs are most welcome!
[jovian] Saving notebook..