-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Refactor fastai metrics and Recorder to improve flexibility #3576
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…to metrics_rewrite
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
To do: Update all the references to and usage of existing functional metrics in tutorials, examples, etc. |
…fastai into metrics_rewrite
Closed due to fastai v2 no longer accepting major changes due to imminent development of fastai v3. Metrics refactor can be used with fastai v2 via fastxtend here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors fastai metrics and
Recorder
to allow metrics to independently compute on train, valid, or both. It allows easy logging of multiple losses, or low-compute metrics during training and low & high-compute metrics during validation without additional callbacks.Motivation
Except for
train_loss
andvalid_loss
,Recorder
is currently setup to log all metrics at train, validation, or both, with no options for fine grained control over metric logging. It is impossible to add a single metric which records during training without writing a callback and duplicating code.Examples where this would be useful: recording individual losses in addition to total loss while performing multi-loss training or recording low-compute metrics during training and low & high-compute metrics during validation.
Overview of Changes
Recorder
andMetric
to allow anyMetric
to independently log on train, valid, or both, with the exception ofAvgSmoothMetric
.AvgSmoothMetric
, a metric version ofAvgSmoothLoss
.func_to_metric
convenience function for defining metrics from functions. This is a more generic version of the currentskm_to_fastai
.AccumMetric
activation function and argmax code toMetric
so all inherited classes can use it.WandbCallback
,AzureMLCallback
, andTensorBoardCallback
to reflect changes.NeptuneCallback
is unchanged as it is deprecated.Defining and Using a New Metric Examples
To define new metrics via the metrics classes:
or with the
func_to_metric
convenience method:Then have TestAvg run on train and TestAccum on valid, you'd set
the logger output would be this:
due to automatic metric name deduping.
Upgrade Path
For those using fastai 2.5.3 or earlier, the upgrade path is to change any functional metrics to a class initialization, eg
Outside of this one required change, this PR should be a drop-in replacement for normal use of the current metrics system.
If someone is setting
train_metrics=False
inRecorder.__init__
, then the upgrade path is to set thelog_metric
argument of the new metrics toLogMetric.Train
orLogMetric.Both
, depending if they kept theRecorder
default ofvalid_metrics=True
or not.Testing
In addition to writing new tests to cover the changes, I have also used this metrics refactor in a project for the past month or so without issue.