LeeJunHyun / Image_Segmentation

Pytorch implementation of U-Net, R2U-Net, Attention U-Net, and Attention R2U-Net.
2.66k stars 594 forks source link

I can't change the batch_size #50

Closed TwinkleStars1029 closed 1 year ago

TwinkleStars1029 commented 4 years ago

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/dataloader.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?

zhangtongzan commented 3 years ago

I also encountered this problem, how to modify it

ActonMartin commented 3 years ago

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.)

apri0426 commented 3 years ago

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