Cutout throws 'Image' object has no attribute 'shape'
See original GitHub issuepytorch-lightning==0.7.6 torchtoolbox==0.1.4.1 torchvision==0.6.0a0+82fd1c8
Loading Images using:
img = Image.open(str(IMAGE_DIR ))) # import PIL.Image as Image
Composing Transforms using:
self.transform_train = transforms.Compose([transforms.Resize((224, 224)),
transforms.RandomHorizontalFlip(0.5),
transforms.RandomVerticalFlip(0.5),
transforms.ColorJitter(0.4, 0.4, 0.4),
Cutout(),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])])
Trace: AttributeError: Caught AttributeError in DataLoader worker process 0. Original Traceback (most recent call last): File “/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py”, line 178, in _worker_loop data = fetcher.fetch(index) File “/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py”, line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File “/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py”, line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File “<ipython-input-30-5eadc434e3d5>”, line 30, in getitem img = self.transform(img) File “/opt/conda/lib/python3.7/site-packages/torchvision/transforms/transforms.py”, line 61, in call img = t(img) File “/opt/conda/lib/python3.7/site-packages/torchtoolbox/transform/transforms.py”, line 1450, in call left, top, h, w, ch = self.get_params(img, self.scale, self.ratio) File “/opt/conda/lib/python3.7/site-packages/torchtoolbox/transform/transforms.py”, line 1433, in get_params img_h, img_w, img_c = img.shape AttributeError: ‘Image’ object has no attribute ‘shape’
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
If you have good idea please make a pr to me.
We could just do a type check and call the function as needed there would be no need to convert the image in that case. Integration with
albumentations
sounds good!