Pytorch-yolov3: TypeError: 'NoneType' object is not subscriptable

Created on 1 Aug 2019  ·  11Comments  ·  Source: eriklindernoren/PyTorch-YOLOv3

Have there anyone else who met the same problem as I met?
It can train in some batch,however meet the error suddenly.
I am sure the path is correct.but I don't know how to solve it
---- [Epoch 0/100, Batch 7/55] ---- +------------+--------------+--------------+--------------+ | Metrics | YOLO Layer 0 | YOLO Layer 1 | YOLO Layer 2 | +------------+--------------+--------------+--------------+ | grid_size | 16 | 32 | 64 | | loss | 53.503120 | 49.941383 | 60.964851 | | x | 0.109302 | 0.079437 | 0.094549 | | y | 0.089693 | 0.093862 | 0.099689 | | w | 1.409947 | 0.991294 | 2.199120 | | h | 0.381467 | 0.345485 | 4.021410 | | conf | 50.943905 | 47.888214 | 53.957447 | | cls | 0.568806 | 0.543090 | 0.592637 | | cls_acc | 2.04% | 0.00% | 12.24% | | recall50 | 0.000000 | 0.000000 | 0.000000 | | recall75 | 0.000000 | 0.000000 | 0.000000 | | precision | 0.000000 | 0.000000 | 0.000000 | | conf_obj | 0.380452 | 0.323845 | 0.408052 | | conf_noobj | 0.388892 | 0.365904 | 0.407760 | +------------+--------------+--------------+--------------+

File "train.py", line 100, in <module> for batch_i, (_, imgs, targets) in enumerate(dataloader): File "/root/anaconda2/envs/keyan/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 568, in __next__ return self._process_next_batch(batch) File "/root/anaconda2/envs/keyan/lib/python3.6/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 "/root/anaconda2/envs/keyan/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/root/anaconda2/envs/keyan/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 99, in <listcomp> samples = collate_fn([dataset[i] for i in batch_indices]) File "/home/yanghanxun/PyTorch-YOLOv3_05/utils/datasets.py", line 130, in __getitem__ img, targets = horisontal_flip(img, targets) File "/home/yanghanxun/PyTorch-YOLOv3_05/utils/augmentations.py", line 8, in horisontal_flip targets[:, 2] = 1 - targets[:, 2] TypeError: 'NoneType' object is not subscriptable

Most helpful comment

I ran into this issue and it ended up being caused by having training images that did not have corresponding labels. I removed the images that did not have annotations and that fixed the problem. Hope that fixes the issue for you as well.

All 11 comments

Hi,I also met the same problem,Have you solved it?
Thanks~

I ran into this issue and it ended up being caused by having training images that did not have corresponding labels. I removed the images that did not have annotations and that fixed the problem. Hope that fixes the issue for you as well.

I ran into this issue and it ended up being caused by having training images that did not have corresponding labels. I removed the images that did not have annotations and that fixed the problem. Hope that fixes the issue for you as well.

oh ,thanks .Maybe I have a bad data set

Hi,I also met the same problem,Have you solved it?
Thanks~

你解决这个问题了吗? 我在datasets.py第100行把
if self.augment: 改为:
if self.augment and targets is not None:
就可以正常运行了,希望对你有帮助

It could be this: your image suffix being uppercase JPG or uppercase PNG causes problems with dataset reading your label_files.You can do it this way:
path.replace("images", "labels").replace(".png", ".txt").replace(".jpg", ".txt")
-->path.replace("images", "labels").replace(".PNG", ".txt").replace(".JPG", ".txt")
Check carefully to see if your label files have been read successfully by debugging

Hi,I also met the same problem,Have you solved it?
Thanks~

你解决这个问题了吗? 我在datasets.py第100行把
if self.augment: 改为:
if self.augment and targets is not None:
就可以正常运行了,希望对你有帮助

other error appear:
/PyTorch-YOLOv3-master/utils/datasets.py", line 142, in collate_fn
targets = torch.cat(targets, 0)
RuntimeError: expected a non-empty list of Tensors

Hi,I also met the same problem,Have you solved it?
Thanks~

你解决这个问题了吗? 我在datasets.py第100行把
if self.augment: 改为:
if self.augment and targets is not None:
就可以正常运行了,希望对你有帮助

灰常感谢!

I ran into this issue and it ended up being caused by having training images that did not have corresponding labels. I removed the images that did not have annotations and that fixed the problem. Hope that fixes the issue for you as well.

It is True, Thank you!

I checked my images and every single one of them has annotations. Removing them is no use, I tried that. I checked that all the suffixes are lowercase too, and I'm unable to run this. Any ideas?

Revisé mis imágenes y cada una de ellas tiene anotaciones. Eliminarlos no sirve de nada, lo intenté. Verifiqué que todos los sufijos también están en minúsculas y no puedo ejecutar esto. ¿Algunas ideas?

could you solve it?

楼主解决了这个问题了吗,我现在也遇到了这个问题,不知道怎么弄了

Was this page helpful?
0 / 5 - 0 ratings