Skip to content

🩹 [Fix] Labels in YOLO detection format #175

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

luuzk
Copy link

@luuzk luuzk commented Feb 21, 2025

This PR fixes a bug where .txt files are always interpreted in YOLO segmentation format (class_id, x1, y1, x2, y2, ..., xn, yn) although they are in very common YOLO detection format (class_id, cx, cy, w, h). This behavior is explained in #141 (comment) and #148 (comment) by @henrytsui000.

Closes #102, #141, #148, and #158.

Adds a new method convert_bboxes to convert bounding boxes to YOLO segmentation format if they are in YOLO detection format. Otherwise, leave them as is for backwards compatibility.

@luuzk luuzk changed the title 🩹 [Fix] YOLO detection format 🩹 [Fix] Labels in YOLO detection format Feb 21, 2025
@minnemint
Copy link

minnemint commented Mar 18, 2025

You saved my life, thank you

@PyBastian
Copy link

Would this mean that the bbox from yolo format, its consider as a 4 points segmentation for the model?

@PyBastian PyBastian mentioned this pull request Mar 24, 2025
@divyanidhi
Copy link

Hi @luuzk
Adding this PR to code does solve the issue of yolo format, but I am not able to get correct inferencing on the custom trained model. Adding image as a reference.
image (12)

Do you have any suggestions on what could be the issue?

@johnk2hawaii
Copy link

johnk2hawaii commented Apr 23, 2025

Thanks for this, I have tried this branch and I am still getting the same problem as always, when I transfer train it ends in a couple of seconds with no error report and a one liner in my output log that says

📈 Enable Model EMA

I have task.ema.enable=True but if I set it to False nothing changes. Working in google colab if that helps.

Cheers

@johnk2hawaii
Copy link

johnk2hawaii commented Apr 24, 2025

I made some progress by altering the dataset folder structure but the error I am getting now is:

Error executing job with overrides: ['task=train', 'task.data.batch_size=5', 'task.ema.enable=True', 'model=v9-s', 'dataset=data.yaml', 'device=cuda', 'task.epoch=10', 'use_wandb=False'] Traceback (most recent call last): File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\lazy.py", line 34, in main model = TrainModel(cfg) File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\tools\solver.py", line 70, in __init__ super().__init__(cfg) File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\tools\solver.py", line 35, in __init__ self.val_loader = create_dataloader(self.validation_cfg.data, self.cfg.dataset, self.validation_cfg.task) File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\tools\data_loader.py", line 225, in create_dataloader dataset = YoloDataset(data_cfg, dataset_cfg, task) File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\tools\data_loader.py", line 39, in __init__ self.img_paths, self.bboxes, self.ratios = tensorlize(self.load_data(Path(dataset_cfg.path), phase_name)) File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\utils\dataset_utils.py", line 127, in tensorlize raise e File "C:\Users\johnk\Desktop\pythonProject\pythonProject2\MITCorrection\YOLO\yolo\utils\dataset_utils.py", line 121, in tensorlize img_paths, bboxes, img_ratios = zip(*data) ValueError: not enough values to unpack (expected 3, got 0)
It looks like the data object is empty. My dataset is in YOLO format looks like this

Xray/
├── images
│ ├── train
│ └── val
├── labels
│ ├── train
│ └── val

my data.yaml file is:

path: /content/YOLO/yolo/config/dataset/data.yaml
train: /content/YOLO/data/Xray/images/train
validation: /content/YOLO/data/Xray/images/valid

train_label_dir: /content/YOLO/data/Xray/labels/train
val_label_dir: /content/YOLO/data/Xray/labels/valid

class_num: 5
names: ['0', '1', '2', '3', '4']

Hoping to get some advice.

@pypoulp
Copy link

pypoulp commented Apr 30, 2025

Hello,

Currently on main, the code accepts annotations in the format (class_id, x1, y1, x2, y2) as well.

Attempting automatic conversion based on:

if len(anno) > 5:
    segmentation_data.append(anno)
    continue

breaks support for this format.

I would suggest introducing a configuration option, allowing users to explicitly specify the annotation format. This would make the behavior clearer and avoid unexpected issues.

@jenhaoyang
Copy link

Use YOLOv8 Format
https://docs.ultralytics.com/datasets/segment/

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

Successfully merging this pull request may close these issues.

Wrong label annotations when training on custom dataset
7 participants