yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

RuntimeError when using "segment/predict.py" with --save-txt

Open Robotatron opened this issue 2 years ago • 1 comments

Search before asking

  • [X] I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

No response

Bug

--save-txt flag errors out with segment/predict.py Was this flag ever supported for segmentation or is it a bug? If it was never supported, do you plan to add support of this flag similar to object detection?

Traceback (most recent call last):
  File "segment/val.py", line 472, in <module>
    main(opt)
  File "segment/val.py", line 443, in main
    run(**vars(opt))
  File "/opt/conda/envs/oneformer/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "segment/val.py", line 319, in run
    save_one_txt(predn, save_conf, shape, file=save_dir / 'labels' / f'{path.stem}.txt')
  File "segment/val.py", line 61, in save_one_txt
    xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
RuntimeError: shape '[1, 4]' is invalid for input of size 36
terminate called without an active exception
Aborted

image

Environment

YOLOv5 🚀 v7.0-53-g65071da Python-3.8.15 torch-1.10.1 CUDA:0 (Tesla V100-SXM2-16GB, 16160MiB)

Minimal Reproducible Example

python segment/predict.py (...) --save-txt

Additional

No response

Are you willing to submit a PR?

  • [ ] Yes I'd like to help by submitting a PR!

Robotatron avatar Jan 04 '23 01:01 Robotatron

@Robotatron I could run the val.py by making the following change

xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() -> xywh = torch.tensor(xyxy).view(-1).numpy()

This just allows the code to run but is not a fix. the coordinates in the txt files are like: 0.465576 68.375 431.75 129.5 462.25 0.916016 1 0.0207062 0.295898 -0.079895 0.636719 -0.351318 0.0551758 0.17981 -0.511719 0.0827637 0.245605 0.175171 0.0436096 0.242432 0.111511 0.188965 0.272461 -0.714844 0.308594 -0.159668 0.0290222 -0.126099 -0.0547791 0.0430908 0.328857 0.127686 0.0599976 0.324463 0.184692 -0.0628052 0.127197 -0.570801

mehran66 avatar Jan 10 '23 17:01 mehran66

This just allows the code to run but is not a fix.

If it runs with the desired output, why is not a fix in your opinion? I assume the class label is given correctly as well, so that we have a full prediction here - a label + the mask/polygon

Robotatron avatar Jan 11 '23 17:01 Robotatron

The numbers look strange...negative coordinates!

mehran66 avatar Jan 11 '23 17:01 mehran66

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

  • Wiki – https://github.com/ultralytics/yolov5/wiki
  • Tutorials – https://docs.ultralytics.com/yolov5
  • Docs – https://docs.ultralytics.com

Access additional Ultralytics ⚡ resources:

  • Ultralytics HUB – https://ultralytics.com/hub
  • Vision API – https://ultralytics.com/yolov5
  • About Us – https://ultralytics.com/about
  • Join Our Team – https://ultralytics.com/work
  • Contact Us – https://ultralytics.com/contact

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

github-actions[bot] avatar Feb 11 '23 00:02 github-actions[bot]

@mehran66 you're right, those negative coordinates do look unusual. It's possible that there might be an issue with the current implementation. I recommend checking if this behavior is occurring in the latest release, and if so, you may want to raise it as an issue to our YOLOv5 GitHub repository. We appreciate your help in improving the YOLOv5 experience for everyone.

glenn-jocher avatar Nov 15 '23 08:11 glenn-jocher