-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Training YOLO v8 Segment Model with COCO Panoptic Dataset type #12680
Comments
👋 Hello @danicannt, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
Hello! Training a YOLO v8 segment model with datasets like RailSem19, which use COCO Panoptic formatting, can indeed pose unique challenges, especially for complex object types like "polyline pair." For handling conversion of "polyline pair" objects, you might need to adapt them into a compatible format that YOLOv8 can process. One common approach is converting these polyline pairs into segmentation masks if your converter allows this transformation. Each polyline could be treated as a boundary of an object for segmentation purposes. If you're writing a custom script for conversion, consider using polygon-based segmentation masks, where each "polyline pair" defines the vertices of a polygon. Libraries such as OpenCV in Python can help you fill polygons based on these vertices, creating masks that YOLO can train on. Here’s a quick snippet to create a mask from polygons using OpenCV: import cv2
import numpy as np
# Example polyline pairs (replace these with actual data)
polyline_pairs = [[[10, 10], [150, 200], [300, 150]], [[50, 50], [200, 250], [350, 200]]]
mask = np.zeros((height, width), dtype=np.uint8) # Specify the dimensions of the image
for polyline in polyline_pairs:
cv2.fillPoly(mask, [np.array(polyline, dtype=np.int32)], 255)
# Now `mask` is your segmentation mask that YOLO can use I hope this helps! Keep exploring, and feel free to share any successful methods you come up with in the community. Happy training! 🚀 |
Hello @glenn-jocher Sorry for the late reply,
I still have some difficulties with the polyline-pair object type. Reading your message has made me realize that maybe there is a way of instead of converting the json files I could use the 8uint files that are as well in the dataset, but what I am not sure of how to do is how to train yolo using this masks as you mentioned |
Hello @danicannt, Thanks for sharing your conversion script! It looks like you've made significant progress. For handling the "polyline-pair" objects, your approach of using the Convex Hull to approximate the object's boundary is quite innovative. 👍 Regarding your idea of using 8-bit uint mask files directly for training, YOLOv8's segmentation models can indeed be trained using mask images if they are properly formatted. Each pixel value in your mask should correspond to a class ID, which the model will use to learn the segmentation task. Here’s a brief outline on how you might adjust your training setup:
Here's a simple example of how you might configure your dataset: # dataset.yaml
train: /path/to/train/images
val: /path/to/val/images
nc: 5 # number of classes
names: ['fence', 'pole', 'traffic-light', 'traffic-sign', 'rail'] And then, you can start training using: yolo segment train data=dataset.yaml model=yolov8n-seg.pt This should help you leverage those mask files directly, potentially simplifying your preprocessing pipeline. Keep experimenting, and don't hesitate to reach out if you hit any snags! 🚀 |
Hi again @glenn-jocher, I'm still struggling with this, sorry to bother you again. I have been able to successfully train YOLO with my label files, but the results are not the best as some of the labels are not well converted. Now I am trying to use these PNG files that are encoded as follows:
I am not interested in all of the classes and will create a new script to alter these images and just keep the ones that I want, but at the moment just being able to train the model would be a success. My folder structure is the following:
This is my YAML file structure:
And I am training it with this configuration:
But I am getting this output when it starts to train; first, it says that my images are background. Do I have to point to where my masks are as well? Maybe I am missing some steps.
|
Hi @danicannt, It looks like the issue might be related to the dataset configuration, particularly how the masks are linked in your YAML file. In your current setup, the model doesn't seem to recognize the mask files, which is why it's treating all images as background. To resolve this, you should specify the path to your masks in the YAML configuration file. Here's how you can adjust your YAML to include masks: train: /home/usuario/workspaces/autotram_ws/data/rs19_val/dataset/images/train
val: /home/usuario/workspaces/autotram_ws/data/rs19_val/dataset/images/val
mask_train: /home/usuario/workspaces/autotram_ws/data/rs19_val/dataset/masks/train
mask_val: /home/usuario/workspaces/autotram_ws/data/rs19_val/dataset/masks/val
nc: 36
names: ['road', 'sidewalk', 'construction', 'tram-track', 'fence', 'pole', 'traffic-light', 'traffic-sign', 'vegetation', 'terrain', 'sky', 'human', 'rail-track', 'car', 'truck', 'trackbed', 'on-rails', 'rail-raised', 'rail-embedded', 'switch-indicator', 'crossing', 'switch-left', 'switch-right', 'rail', 'track-sign-front', 'track-signal-front', 'platform', 'buffer-stop', 'guard-rail', 'train-car', 'switch-unknown', 'switch-static', 'track-signal-back', 'rail-occluder', 'person-group', 'person'] Make sure that your mask files are correctly formatted and correspond to each image file by name. This should help the model recognize and use the masks during training. If the issue persists, double-check the format of your mask files to ensure they are compatible with YOLOv8's expectations (i.e., each pixel value directly corresponds to a class ID). Hope this helps! Let me know how it goes. 🚀 |
Hi @glenn-jocher still getting the same issue, I have adapt my dataset because there were some pixels that were 255 as value. Iterate through all the dataset and changed them to '36' as value so in the yaml file I've added a new class as 'other' being the last class: this is my yaml file now:
I have add an additional check for my files to see if the masks format was correct and see max and min value of each image pixels and this is the the output:
But when training the model I am still getting this output:
Sorry to bother you with this problem, but learning how to properly train Yolo with masks would be really useful, also I am attaching one mask image as an example of how they are |
Also by mistake I have changed the masks directories while the model was training and I have seen that it is doing something with the masks because It started publishing this, so it seems it is doing something with the png files apparently, but it still crashes:
The folder structure that I am using now is this one:
|
@danicannt hi there! It seems like the model is indeed attempting to access the mask files, but there are issues with file paths or file integrity based on the warnings you're seeing. This could be due to incorrect paths in your dataset configuration or issues with the mask files themselves. Here are a couple of things to check and try:
train: /path/to/dataset/train/images
val: /path/to/dataset/val/images
mask_train: /path/to/dataset/train/masks
mask_val: /path/to/dataset/val/masks
nc: 37
names: ['road', 'sidewalk', 'construction', 'tram-track', 'fence', 'pole', 'traffic-light', 'traffic-sign', 'vegetation', 'terrain', 'sky', 'human', 'rail-track', 'car', 'truck', 'trackbed', 'on-rails', 'rail-raised', 'rail-embedded', 'switch-indicator', 'crossing', 'switch-left', 'switch-right', 'rail', 'track-sign-front', 'track-signal-front', 'platform', 'buffer-stop', 'guard-rail', 'train-car', 'switch-unknown', 'switch-static', 'track-signal-back', 'rail-occluder', 'person-group', 'person', 'other'] Make sure the paths are correct and point directly to the folders containing the images and masks. If these steps don't resolve the issue, it might be helpful to look at the logs for any additional errors or warnings that could give more insight into what might be going wrong. Keep us posted on your progress! 🚀 |
Hi @glenn-jocher , How can I activate the logs to check what is happening? Also, do you know from any dataset with which I can compare the structure that successfully trains with masks and so? I am gonna keep trying this week, will keep you updated |
Hi @danicannt, To activate detailed logging, you can set the Regarding datasets, you might want to look at the COCO dataset, which is a well-structured and commonly used dataset for segmentation tasks. It can serve as a good reference for your dataset structure. Feel free to keep us updated on your progress, and we're here to help if you have any more questions! 🚀 |
Search before asking
Question
Hello everyone,
I'm currently trying to training a YOLO v8 segment model using the RailSem19 dataset, which follows the format of the COCO Panoptic dataset. However, I've encountered some challenges during the conversion process.
There are certain object types labeled as "polyline pair" within the RailSem19 dataset that I'm unsure how to properly convert for training with YOLO v8. I found some converters but I haven't been able to achieve successful conversion due to these object types.
I'm reaching out to inquire if anyone in the community has attempted or achieved success in training YOLO v8 with datasets similar to RailSem19 or has insights on how to handle "polyline pair" objects during conversion. Any guidance you can share would be helpful.
Thank you in advance
Additional
No response
The text was updated successfully, but these errors were encountered: