-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
labels4.append(labels) UnboundLocalError: local variable 'labels' referenced before assignment #548
Comments
I have the same bug:
Traceback (most recent call last): |
I only one class |
In my case, it was because the train dataset contained an empty label file. |
|
Examining the whole label files, finding files of size 0, and deleting the label file and corresponding image. Then, create a txt file containing the image paths again.
|
@Belinda-great I'm seeing your same error (I have 24 classes instead of 1), but have no empty files, nor mismatch in files between labels & images. Did you have any luck resolving? (py3) user$ python3 train.py --data data/coco.data --cfg cfg/yolov3.cfg Reading labels (4824 found, 16 missing, 0 empty for 4840 images): 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4840/4840 [00:01<00:00, 3131.97it
it]Traceback (most recent call last): |
I fixed this error after I uncommented a line in datasets.py, (line 330) to discover the problematic files and deleted them. I had sufficient samples that this wasn't a problem, but for some datasets that might not be the case. I also could not deduce from close inspection what the difference was between these labels and other labels. Ideally, if this type of data error will prevent the model training, it should exit prior to starting the process. |
@glenn-jocher, I just add a tab in line, maybe fix? Line 590 in 09ca721
|
@mozpp @willsroberts @rms0329 @xiaotian3 @Belinda-great @Samjith888 the latest commit should fix this: aae39ca The error was caused because some images in your custom dataset lacked labels, so this predefines an empty labels array for all images, which is replaced by actual labels if they are present. Can you |
@glenn-jocher previously had the same error as those above. After pulling (so that I'm to date as of this post) and trying again, I run into the following error:
I'm assuming this had something to do with the fix; the code runs fine if I remove the empty label files. |
@bchugg thanks for the feedback. This means it's trying to stack the np.arrays with the [] repopulated arrays. We want to make these 0xn np arrays, so I've updated the code to this now. Can you try again? Thanks! Lines 582 to 592 in 470ef6b
|
@glenn-jocher all good on my end now! Cheers :). |
Great! I'll close this issue for now as the original issue appears to have been resolved, and/or no activity has been seen for some time. Feel free to comment if this is not the case. |
yolov5/utils/general.py", line 75, in check_git_status |
the train set must not have a image that has no object in it????? |
@henbucuoshanghai thanks for the bug report. This is related to a recent PR ultralytics/yolov5#1916 (unrelated to your dataset). I will take a look. |
@henbucuoshanghai we've identified the problem and created and merged a bug fix PR #1660 for this. Please Thank you for your contributions! |
I have replaced coco dataset with own datasets, which have only one class ('person'). While training, i got the following error.
`
(base) C:\Users\samjith.cp\Desktop\yolov3>python train.py --data coco.data --cfg cfg/yolov3.cfg
Namespace(accumulate=2, adam=False, arc='defaultpw', batch_size=32, bucket='', cache_images=False, cfg='cfg/yolov3.cfg', data='coco.data', device='', epochs=273, evolve=False, img_size=416, img_weights=False, multi_scale=False, name='', nosave=False, notest=False, prebias=False, rect=False, resume=False, transfer=False, var=None, weights='')
Using CPU
WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
Reading labels (357 found, 0 missing, 4 empty for 361 images): 100%|███████████████| 361/361 [00:00<00:00, 6489.34it/s]
Model Summary: 222 layers, 6.19491e+07 parameters, 6.19491e+07 gradients
Starting training for 273 epochs...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
0%| | 0/12 [00:00<?, ?it/s]Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Traceback (most recent call last):
File "train.py", line 426, in
train() # train normally
File "train.py", line 235, in train
for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\tqdm_tqdm.py", line 1005, in iter
for obj in iterable:
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 819, in next
return self._process_data(data)
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 846, in _process_data
data.reraise()
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch_utils.py", line 369, in reraise
raise self.exc_type(msg)
UnboundLocalError: Caught UnboundLocalError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data_utils\worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\samjith.cp\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\samjith.cp\Desktop\yolov3\utils\datasets.py", line 416, in getitem
img, labels = load_mosaic(self, index)
File "C:\Users\samjith.cp\Desktop\yolov3\utils\datasets.py", line 590, in load_mosaic
labels4.append(labels)
UnboundLocalError: local variable 'labels' referenced before assignment`
The text was updated successfully, but these errors were encountered: