hi i wrote codes for object detection using YoloV5 in Google Colab. i have some google earth images that i saved in my Google Drive Storage. i am using “Append” method in a list, but my list is empty after run codes in Google Colab. below image is Code snippets:
Please read the pinned thread and show code as properly formatted, copied and pasted text. Also, we can only possibly talk about the part of the code that is actually shown to us: in order to understand what went wrong with using the append method, we need to see the code that has append in it.
We actually need you to copy and paste and format the code so we can copy it and run it on our own machines to help you.
On the machine you are running this code, you are logged into Google Drive, right? Your login didn’t time out? That is required when using Colab and Google Drive access.
IndexError Traceback (most recent call last)
in <cell line: 54>()
53
54 for x in range(countfortrain):
—> 55 fileJpg = choice(imgs)
56 fileXml = fileJpg[:-4] +‘.txt’
57
/usr/lib/python3.10/random.py in choice(self, seq)
376 “”“Choose a random element from a non-empty sequence.”“”
377 # raises IndexError if seq is empty
→ 378 return seq[self._randbelow(len(seq))]
379
380 def shuffle(self, x, random=None):
It isn’t clear to me what’s wrong with your code, and I haven’t got your
training data here.
I would put a print(imgs) at strategic points, for example before and
after the for-loops, before and after the imgs.remove() calls, and
before line 55 where you call choice().
The only way to get an index error from choice() is for the list you
give it to be empty, example:
>>> choice([1])
1
>>> choice([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cameron/var/pyenv/versions/3.10.6/lib/python3.10/random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
IndexError: list index out of range
Hopefully the print() calls can show you where the imgs list is
becoming not what you intended. You should put a littl context in the
prints, eg:
Return a random element from the non-empty sequence seq. If seq is empty, raises IndexError."
And you have an IndexError.
Step through your program line by line and check the value of imgs at various points. See if it gets initialized to blank at some point. Does Colab has a debugger for python?
but i have a new error for below codes:
!python train.py --img 416 --batch 16 --epochs 10 --data dataset.yaml --weights yolov5s.pt
my new error is :
python3: can’t open file ‘/content/train.py’: [Errno 2] No such file or directory
The command python train.py ..... tells Python to open the programme in the file train.py in the current working directory. So Python is being run in the directory /content.
this file is in content/yolov5 and i downloaded this file then i uploaded into content directory and solved error.
Now colab shows new error:
Traceback (most recent call last):
File “/content/train.py”, line 47, in
import val as validate # for end-of-epoch mAP
ModuleNotFoundError: No module named ‘val’