Similar to #145 . Command used:
python3 test.py --weights_path ../weights/yolov3.weights --class_path='data/coco.names' --data_config=../rover/config/coco.data
Stack Trace:
Namespace(batch_size=8, class_path='data/coco.names', conf_thres=0.001, data_config='../rover/config/coco.data', img_size=416, iou_thres=0.5, model_def='config/yolov3.cfg', n_cpu=8, nms_thres=0.5, weights_path='../weights/yolov3.weights')
Compute mAP...
Detecting objects: 27% 167/625 [01:23<04:30, 1.69it/s]Traceback (most recent call last):
File "test.py", line 98, in <module>
batch_size=8,
File "test.py", line 36, in evaluate
for batch_i, (_, imgs, targets) in enumerate(tqdm.tqdm(dataloader, desc="Detecting objects")):
File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 979, in __iter__
for obj in iterable:
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 637, in __next__
return self._process_next_batch(batch)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
RuntimeError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/content/PyTorch-YOLOv3/utils/datasets.py", line 146, in collate_fn
imgs = torch.stack([resize(img, self.img_size) for img in imgs])
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 1 in dimension 1 at /pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1307
The shape of image #1339 is 427x640 with no channels a/c:
Detecting objects: 27% 1339/5000 [02:44<06:53, 8.85it/s](427, 640)
This is what's crashing the testing. Time and Again. But how is that possible? The following is the img_path:
coco/images/val2014/COCO_val2014_000000154053.jpg
The collate_fn maybe does not account for images with only 2 dims?
I have the same issue, have you solved yet?
I have solved the problem by adding .convert('RGB') in utils/dataset.py ListDataset' function __getitem__
original:
img = transforms.ToTensor()(Image.open(img_path))
modified and worked:
img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))
I have solved the problem by adding .convert('RGB') in utils/dataset.py ListDataset' function getitem
original:
Extract image as PyTorch tensor
img = transforms.ToTensor()(Image.open(img_path))
modified and worked:
Extract image as PyTorch tensor
img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))
thanks so much!!
please pull your code for other victim.
@lizhaoliu-Lec If that works then you are God. Are you getting the mAP scores?
@EverWinter23
I have tried the following commands:
which all worked for me.
python3 test.py --weights_path weights/yolov3.weights
python3 detect.py --image_folder data/samples/
When testing with the pretrained weight---yolov3.weights, I don't remember so clearly, but I have got about 50 mAP.
Now I'm training the network from scratch.
While training, I got the following error:
Then I add the following code on top of utils/datasets.py
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
Now, Training is ok. I have trained for serveral epochs.
@lizhaoliu-Lec Thanks. You're a life saver. Works!!!
Most helpful comment
I have solved the problem by adding .convert('RGB') in utils/dataset.py ListDataset' function __getitem__
original:
Extract image as PyTorch tensor
img = transforms.ToTensor()(Image.open(img_path))
modified and worked:
Extract image as PyTorch tensor
img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))