ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.07k stars 16.42k forks source link

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

Closed Robotatron closed 1 year ago

Robotatron commented 1 year ago

Search before asking

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?

mehran66 commented 1 year ago

@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

Robotatron commented 1 year ago

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

mehran66 commented 1 year ago

The numbers look strange...negative coordinates!

github-actions[bot] commented 1 year ago

πŸ‘‹ 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:

Access additional Ultralytics ⚑ resources:

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 ⭐!

glenn-jocher commented 1 year ago

@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.