Fix mixed image channel sizes in image classifiers#678
Open
Creylay wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
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.
Summary
Image classifiers (MLP, CNN, LeNet5) failed when training on datasets containing images with mixed channel formats and/or class-imbalanced splits. Two independent bugs were fixed:
torch.stackto fail when a batch mixed grayscale, RGB, and RGBA images.label_to_idxwas built only from training split labels, so classes with no training examples (present only in validation) had no index. This causedprepare_outputto produce a mixed int/string list that PyArrow could not convert.Type of Change
Changes (by file)
DashAI/back/models/mlp_image_classifier.py: addedconvert("RGB")to transform pipeline; buildlabel_to_idxfromCategorical.categories(full dataset class list) instead of training split labels; changedprepare_outputfallback from string to-1.DashAI/back/models/cnn_image_classifier.py: same fixes.DashAI/back/models/lenet5_image_classifier.py: same fixes.DashAI/back/models/base_torchvision_image_classifier.py: label index fixes only (convert("RGB")was already present).Testing
Train any image classification model on a dataset that:
RuntimeError: stack expects each tensor to be equal size.ArrowInvalid: tried to convert to int64ory_true contains values {-1}.