-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ImageClassifier with ExponentialLRDecay: metrics not updated/calculated during validation #4807
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
Comments
After looking into some blog posts, I found that my point about the learning rate decaying too soon might be invalid. |
I created a minimal working example based on the DeepLearning_ImageClassification_Training example, that reproduces the bug here.
|
Hi @gartangh , Thank you so much for bringing this issue to our attention, and providing a good repro. I successfully replicated your repro with our local ML.NET build and confirmed the issue. I figured out that the problem with cross entropy during validation is that it simply isn't being updated in validation metrics, as it is missing in the below code snippet: machinelearning/src/Microsoft.ML.Vision/ImageClassificationTrainer.cs Lines 1043 to 1048 in bb13d62
The reason why learning rate is not decreasing during validation is because learning rate schedulers, which machinelearning/src/Microsoft.ML.Vision/ImageClassificationTrainer.cs Lines 1031 to 1041 in bb13d62
I don't see a reason why we don't support learning rate schedulers during validation, and as a result believe the learning rate during validation should also be decreasing due to the I'll be making a PR to address this issue and add tests to verify the changes soon. In addition, I see that you add to manually log the learning rate and cross-entropy to see this bug. I see that these metrics are not reported during validation by default: machinelearning/src/Microsoft.ML.Vision/ImageClassificationTrainer.cs Lines 170 to 179 in bb13d62
I wonder if this gives a hint on whether or not learning rates should be updated during validation with ExponentialLRDecay . I'm in favor of printing these metrics during validation as well.
|
Hi @mstfbl , You're welcome. I'm happy that I could be of help. My guess is that the main part of this issue could be solved by copying that part of the code from training to validation? About the learning rate during validation: one option would be to remove the About your addition: if the cross-entropy is correctly updated, it must certainly be reported as well. It would be really awesome if the output signature would be exactly the same, i.e. also reporting the learning rate. public override string ToString()
{
return $"Phase: Training, Dataset used: {DatasetUsed.ToString(),10}, Batch Processed Count: {BatchProcessedCount,3}, Learning Rate: {LearningRate,10} " +
$"Epoch: {Epoch,3}, Accuracy: {Accuracy,10}, Cross-Entropy: {CrossEntropy,10}";
} |
Hi @gartangh, Thank you once again for notifying us about this issue. My now merged PR #5255 added cross entropy metric support for validation training. I did not add learning decay support for validation, as during validation there is no real training being done, so learning rate decay is not applicable here. |
Hi @mstfbl I just verified your changes by building the master branch locally. Thank you very much for your work. |
Of course, anytime @gartangh ! Please feel free to make more issues/feature requests if you see any in the future, and I hope you continue to enjoy using ML.NET! |
System information
Issue
What did you do?
I am trying to train an image classifier that makes use of
ExponentialLRDecay
.I would like to see the metrics for training and validation for each epoch.
(I added
+ $" CrossEntropy: {metrics.Train.CrossEntropy}, LearningRate: {metrics.Train.LearningRate}"
, because the crossentropy and learning rate are not printed by default for the validation set.)What happened?
2
fornumEpochsPerDecay
inExponentialLRDecay()
, but after the first instead (seen on the third row in the image). After that, the learning rate is correctly updated every 2 epochs. I'm not sure if this is the expected behavior.What did you expect?
Accuracy
and lowestCrossEntropy
are the best, so if 2 models perform equally well in terms of accuracy, the one with the lowest cross-entropy on the validation set should be picked.The text was updated successfully, but these errors were encountered: