pytorch-cutpaste icon indicating copy to clipboard operation
pytorch-cutpaste copied to clipboard

Loading images error

Open zhangyumo95 opened this issue 3 years ago • 4 comments

Traceback (most recent call last): File "run_training.py", line 263, in workers=args.workers) File "run_training.py", line 104, in run_training batch_idx, data = next(dataloader_inf) File "run_training.py", line 93, in get_data_inf for out in enumerate(dataloader): File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in next data = self._next_data() File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data return self._process_data(data) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data data.reraise() File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop data = fetcher.fetch(index) File "/home/ty/anaconda3/envs/mmdet211/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 "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/work/Anomaly_det/pytorch-cutpaste-master/dataset.py", line 43, in getitem img = self.transform(img) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 67, in call img = t(img) File "/home/work/Anomaly_det/pytorch-cutpaste-master/cutpaste.py", line 143, in call org, cutpaste_normal = self.normal(img) File "/home/work/Anomaly_det/pytorch-cutpaste-master/cutpaste.py", line 68, in call patch = self.colorJitter(patch) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 1115, in forward img = F.adjust_hue(img, hue_factor) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 712, in adjust_hue return F_pil.adjust_hue(img, hue_factor) File "/home/ty/anaconda3/envs/mmdet211/lib/python3.7/site-packages/torchvision/transforms/functional_pil.py", line 197, in adjust_hue np_h = np.array(h, dtype=np.uint8) TypeError: array() takes 1 positional argument but 2 were given

zhangyumo95 avatar Jul 13 '21 08:07 zhangyumo95

strange Error. I would check 2 things:

  1. Check if the dataloader can load the images:
from dataset import MVTecAT
from matplot.pyplot import plt

test_data= MVTecAT("Data", "metal_nut")

img = test_data[0]
plt.imshow(test_data[0])
  1. Check if ColorJitter is working on PIL Images as expected:
from torchvision import transforms

colorJitter = transforms.ColorJitter(brightness = 0.1,
                                                      contrast = 0.1,
                                                      saturation = 0.1,
                                                      hue = 0.1)

# load some PIL image into img (you can also just use the code from above)
color_jittered_img = colorJitter(img)
plt.imshow(color_jittered_img)

In both cases you should see an image plot. Let me know if this works

Runinho avatar Jul 22 '21 07:07 Runinho

from dataset import MVTecAT
from matplot.pyplot import plt

test_data= MVTecAT("Data", "metal_nut")

img = test_data[0]
plt.imshow(test_data[0])

Has this problem been solved?I have the same problem

mouxinyue1 avatar Apr 19 '22 07:04 mouxinyue1

TypeError: array() takes 1 positional argument but 2 were given

Maybe this issue is related to: https://github.com/pytorch/pytorch/issues/61125#issuecomment-872624273

Runinho avatar Jul 09 '22 00:07 Runinho

size arg missing error:

test_data= MVTecAT("Data", "metal_nut",1)

worked 4 me.

danielsoy avatar Apr 07 '23 02:04 danielsoy