Image_Segmentation icon indicating copy to clipboard operation
Image_Segmentation copied to clipboard

I can't change the batch_size

Open TwinkleStars1029 opened this issue 5 years ago • 3 comments

Whenever I modify the batch_size, the program does not run, and then I refer to this issue #4 to modify it. I followed your suggestion "change the code data_loader.py#L82 to Transform.append(T.Resize(224,224))", still got the error message.

my code

Transform.append(T.Resize((int(256*aspect_ratio)-int(256*aspect_ratio)%16,256)))
Transform.append(T.Resize(224,224))
Transform = T.Compose(Transform)

Traceback (most recent call last): File "main.py", line 101, in main(config) File "main.py", line 61, in main solver.train() File "/home/en308/pytorch/Image_Segmentation-master/solver.py", line 142, in train for i, (images, GT) in enumerate(self.train_loader): File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 582, in next return self._process_next_batch(batch) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 608, in _process_next_batch raise batch.exc_type(batch.exc_msg) TypeError: Traceback (most recent call last): File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/utils/worker.py", line 99, in samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/en308/pytorch/Image_Segmentation-master/data_loader.py", line 89, in getitem image = Norm(image) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 164, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 201, in normalize raise TypeError('tensor is not a torch image.') TypeError: tensor is not a torch image.

I see the data_loader.py#L81 process same question

so I modify

Transform.append(T.Resize(224,224))
Transform.append(T.ToTensor())
Transform = T.Compose(Transform)

Traceback (most recent call last): File "main.py", line 101, in main(config) File "main.py", line 61, in main solver.train() File "/home/en308/pytorch/Image_Segmentation-master/solver.py", line 142, in train for i, (images, GT) in enumerate(self.train_loader): File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 582, in next return self._process_next_batch(batch) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 608, in _process_next_batch raise batch.exc_type(batch.exc_msg) ValueError: Traceback (most recent call last): File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/en308/pytorch/Image_Segmentation-master/data_loader.py", line 85, in getitem image = Transform(image) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in call img = t(img) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 196, in call return F.resize(img, self.size, self.interpolation) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 244, in resize return img.resize((ow, oh), interpolation) File "/home/en308/anaconda3/envs/pytorch/lib/python3.7/site-packages/PIL/Image.py", line 1865, in resize message + " Use " + ", ".join(filters[:-1]) + " or " + filters[-1] ValueError: Unknown resampling filter (224). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

Could you suggest me how to do?

TwinkleStars1029 avatar Feb 14 '20 02:02 TwinkleStars1029

I also encountered this problem, how to modify it

zhangtongzan avatar Nov 17 '20 01:11 zhangtongzan

I also encountered this problem, how to modify it.

Because one transform is a list, another one transform is a pytorch function. You should change the function's name to 'transformed'(any name you like.)

ActonMartin avatar Dec 07 '20 12:12 ActonMartin

use Transform.append(T.Resize((224,224))) instead of Transform.append(T.Resize(224,224))

apri0426 avatar Dec 11 '20 11:12 apri0426