Fix batch classification TypeError when using data_path (#611)#616
Open
jQuinRivero wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix batch classification TypeError when using data_path (#611)#616jQuinRivero wants to merge 1 commit intomicrosoft:mainfrom
jQuinRivero wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…\n\nReplace pw_data.ImageFolder with pw_data.ClassificationImageFolder in\nboth timm_base and resnet_base classifiers, and remove the invalid\npath_head keyword argument that ImageFolder does not accept.\n\nImageFolder.__getitem__ is abstract (returns None), so the correct\nsubclass for classification is ClassificationImageFolder, which returns\nthe (img, img_path) tuple the dataloader loop expects.\n\nAlso export ClassificationImageFolder from datasets __all__."
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.
Fixes #611
Problem
Calling
batch_image_classification(data_path=...)on any TIMM-based or ResNet-based classifier raises aTypeErrorbecausepw_data.ImageFolderdoes not accept apath_headkeyword argument:Additionally,
ImageFolderis the abstract base class whose__getitem__returnsNone, so even if the kwarg issue were fixed, the dataloader would fail to unpack(img, img_path).Fix
pw_data.ImageFolderwithpw_data.ClassificationImageFolder— the correct subclass that implements__getitem__returning(img, img_path).path_head='.'argument (ClassificationImageFolderbuilds full paths viaos.walk, sopath_headis unnecessary).ClassificationImageFolderto__all__indatasets.pyfor export consistency.Files changed
PytorchWildlife/data/datasets.pyClassificationImageFolderto__all__PytorchWildlife/models/classification/timm_base/base_classifier.pyImageFolder→ClassificationImageFolder, removedpath_headPytorchWildlife/models/classification/resnet_base/base_classifier.pySafety
det_resultscode path (usingDetectionCrops) is untouched —path_headis valid there.pw_data.ImageFolder.DetectionImageFoldercorrectly.