Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object is not subscriptable #256

Closed
yhx0105 opened this issue Aug 1, 2019 · 13 comments
Closed

TypeError: 'NoneType' object is not subscriptable #256

yhx0105 opened this issue Aug 1, 2019 · 13 comments

Comments

@yhx0105
Copy link

yhx0105 commented Aug 1, 2019

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

@xiaoxiaoshu111
Copy link

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

@tyjcalvert
Copy link

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.

@yhx0105
Copy link
Author

yhx0105 commented Aug 20, 2019

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

@yhx0105
Copy link
Author

yhx0105 commented Aug 20, 2019

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:
就可以正常运行了,希望对你有帮助

@Shiny-ZhangXiXin
Copy link

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

@Note-Liu
Copy link

Note-Liu commented Jan 4, 2020

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

@kravrolens
Copy link

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:
就可以正常运行了,希望对你有帮助

灰常感谢!

@kravrolens
Copy link

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!

@luisete2
Copy link

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?

@juagvera
Copy link

juagvera commented Dec 4, 2020

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?

@chaishazi
Copy link

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

@Flova
Copy link
Collaborator

Flova commented Jun 15, 2021

This part of the code has been updated or removed. I, therefore, close this issue now. Feel free to reopen for further discussion.

@Flova Flova closed this as completed Jun 15, 2021
@JaGuzmanT
Copy link

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.

Thank you very much. I tried with half of my dataset in order to get out the incomplete or erroneous labels and I finally could identify the labels with problems. Greets!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests