Skip to content

Segment with 3 points #6931

Closed
Closed

Description

@yeldarby

Search before asking

Question

I'm working on adding polygon support to Roboflow annotations so folks can benefit from your copy-paste augmentation when training their custom datasets.

I'm looking at the YOLOv5 segmentation dataloader as implemented here and it looks like a polygon annotation requires at least 4 points to be considered a segment vs a box. I also saw @glenn-jocher mention a minimum of 9 columns here.

How should a triangle (7 columns, class x1 y1 x2 y2 x3 y3) be represented? Should I pad it with a 4th point that's a duplicate of the first?

Additional

No response

Activity

  1. github-actions commented on Mar 10, 2022

    @github-actions
    Contributor

    👋 Hello @yeldarby, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

    If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

    If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

    For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

    Requirements

    Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

    git clone https://github.com/ultralytics/yolov5  # clone
    cd yolov5
    pip install -r requirements.txt  # install

    Environments

    YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

    Status

    CI CPU testing

    If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

  2. glenn-jocher commented on Mar 10, 2022

    @glenn-jocher
    Member

    @yeldarby oh hey good question! Yes, segmentation labels benefit from access to copy-paste augmentation, but also from smarter box cropping during 'normal' (scale, rotate, translate) augmentation, solving the issue below in #2151.

    image

    You can see an example of segmentation labels vs box labels here:

    About how to handle a triangle, I didn't account for triangle shapes originally as I thought each segment would have at least 4 vertices. The logic implementing this is here, which will assume any row with > 8 columns to be a segment annotation instead of a box annotation. I think this should be reducible to > 6 though, which would then be able to accomodate triangle segments. I'll create a PR to test for any side effects of the change.

    yolov5/utils/datasets.py

    Lines 907 to 913 in 055e72a

    with open(lb_file) as f:
    lb = [x.split() for x in f.read().strip().splitlines() if len(x)]
    if any([len(x) > 8 for x in lb]): # is segment
    classes = np.array([x[0] for x in lb], dtype=np.float32)
    segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in lb] # (cls, xy1...)
    lb = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh)
    lb = np.array(lb, dtype=np.float32)

  3. added a commit that references this issue on Mar 10, 2022
  4. yeldarby commented on Mar 10, 2022

    @yeldarby
    Author

    Awesome! I'll allow 3-vertex exports to YOLOv5 format on our end & revisit+revert if it turns out there are side-effects and that PR can't be merged.

  5. added a commit that references this issue on Mar 10, 2022
  6. glenn-jocher commented on Mar 10, 2022

    @glenn-jocher
    Member

    @yeldarby good news 😃! Your original issue may now be fixed ✅ in PR #6938. This PR allows for 3-point segment labels containing 7 columns: (class xy1 xy2 xy3). Tests show no ill effects on normal and segment COCO128 training.

    To receive this update:

    • Git – git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
    • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
    • Notebooks – View updated notebooks Open In Colab Open In Kaggle
    • Docker – sudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

    Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

  7. Steinwang commented on Apr 2, 2022

    @Steinwang

    Awesome! I'll allow 3-vertex exports to YOLOv5 format on our end & revisit+revert if it turns out there are side-effects and that PR can't be merged.

    Hello,I'm using YOLOv5 for a detection and segmentation network, may I ask how you get segment in pbar? I'm in trouble with it,Thanks

  8. glenn-jocher commented on Apr 2, 2022

    @glenn-jocher
    Member

    @Steinwang what's pbar?

  9. added a commit that references this issue on May 24, 2023
  10. added a commit that references this issue on Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions