-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Using an ImageClassificationTrainer with a dataset that only contains one class of images #4660
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
I believe the core of this problem is in the
Since
It's thrown because it can't find the So, for instance, if I were to remove the Whereas, if I train it using a dataset with more than 1 label, then the annotations are as follows (notice the KeyValues annotation): The exact reason of why the Particularly, I also noticed that the Annotations for the machinelearning/src/Microsoft.ML.Data/Scorers/MulticlassClassificationScorer.cs Lines 484 to 489 in b045e4d
If And even though I haven't fully figured out how does the missing annotations in the |
So I've just talked with @codemzs and we decided the best option is to simply throw an exception in here if
Instead of trying to make all the different changes required to support the corner case of having only 1 class represented on the dataset. |
Issue
What did you do?
I tried to train a model that uses the
ImageClassificationTrainer
, using a dataset that only contains images labeled as 'dog'.What happened?
I got a
System.InvalidOperationException: 'Metadata KeyValues does not exist'
while fitting the model, which isn't very informative about the problem. If I didn't know my dataset only contained one label, or if I were to split the dataset in a way that the training set had only one label, then getting that exception wouldn't help to fix the problem.Also notice that the exception is thrown after training is done, so an user would have already invested time on it before noticing that something is wrong.
Probably an exception which tells me that there is only one class in my dataset, as done by other multiclass trainers such as the Multiclass LightGBM which throws a
"System.InvalidOperationException: 'LightGBM Error, code is -1, error message is 'Number of classes should be specified and greater than 1 for multiclass training'.'"
, or theLinearMulticlassModelParametersBase
which throws aSystem.ArgumentOutOfRangeException: 'Must be at least 2. Parameter name: numClasses'
in here.If I changed my dataset to include other labels, then the exception is gone and it works as expected.
Source code / logs
dataset.zip
Nugets used:
The text was updated successfully, but these errors were encountered: