-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
SegformerFeatureExtractor
trying to access non-existent .ndim
attribute
#14332
Comments
.ndim
attributeSegformerFeatureExtractor
trying to access non-existent .ndim
attribute
I did some more debugging on this and it looks like the problem is with the application of The Looks like this wasn't caught in existing tests because none of the test cases include use of the Here is a debugger session where the (Pdb) segmentation_maps[0]
<PIL.Image.Image image mode=L size=512x512 at 0x7F92606119A0> and that it is still a (Pdb) image
<PIL.Image.Image image mode=L size=512x512 at 0x7F92606119A0> Full debugger session > /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(476)__call__()
-> segmentation_maps = [
(Pdb) segmentation_maps[0]
<PIL.Image.Image image mode=L size=512x512 at 0x7F92606119A0>
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(478)__call__()
-> for map in segmentation_maps
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(476)__call__()
-> segmentation_maps = [
(Pdb) s
--Call--
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(476)<listcomp>()
-> segmentation_maps = [
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(476)<listcomp>()
-> segmentation_maps = [
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(478)<listcomp>()
-> for map in segmentation_maps
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(477)<listcomp>()
-> self.pad(map, size=self.crop_size, padding_value=self.segmentation_padding_value)
(Pdb) s
--Call--
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(315)pad()
-> def pad(self, image, size, padding_value=0):
(Pdb) s
> /opt/miniconda3/envs/transformers-bug/lib/python3.8/site-packages/transformers/models/segformer/feature_extraction_segformer.py(331)pad()
-> is_2d = False
(Pdb) image
<PIL.Image.Image image mode=L size=512x512 at 0x7F92606119A0> |
Thanks for your interest in SegFormer! Indeed, you are totally right. The reason is that images get normalized before passing to the self.pad method, and the normalization method turns them into NumPy arrays, whereas segmentation maps are still PIL images. Will fix this today! Together with some additional documentation updates. Thanks for reporting! |
Environment info
transformers
version: 4.12.3Who can help
@NielsRogge or @sgugger
Information
Model I am using (Bert, XLNet ...): Segformer
The problem arises when using:
The tasks I am working on is:
I am trying to fine-tune Segformer with a set of annotated images. When I run
SegformerFeatureExtractor
with a list of PIL files, I get anAttributeError
when it tries to access a.ndim
attribute of the image.It seems like this might be a bug?
image.ndim
is expecting a numpy array but I think it is being passed aPIL.Image
object.To reproduce
Steps to reproduce the behavior:
PIL
objectsSegformerFeatureExtractor
PIL
objects to feature extractorExpected behavior
I expect that the
SegformerFeatureExtractor
object can accept lists ofPIL.Image
objects, as specified in the docs. More practically, I think that the.pad()
method needs to coerce theimage
parameter to a numpy array before doing thendim
check.The text was updated successfully, but these errors were encountered: