-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Why doesn't ".crop()" or "--save-crop" do any cropping? #9585
Comments
@jmiller-dr 👋 Hello! Thanks for asking about cropping results with YOLOv5 🚀. Cropping bounding box detections can be useful for training classification models on box contents for example. This feature was added in PR #2827. You can crop detections using either detect.py or YOLOv5 PyTorch Hub: detect.pyCrops will be saved under python detect.py --save-crop YOLOv5 PyTorch HubCrops will be saved under import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom
# Images
img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
# Inference
results = model(img)
# Results
crops = results.crop(save=True)
# -- or --
crops = results.crop(save=True, save_dir='runs/detect/exp') # specify save dir Good luck 🍀 and let us know if you have any other questions! |
@jmiller-dr just tested myself, crops work correctly for me, I'm not able to reproduce any problem: |
Thanks, yes I already tried both methods and neither work. This should
probably be converted into a "Bug". Or, if not a true bug since it works for others, then a "persistent anomaly affecting some users".
I suppose I can work around by doing manual cropping.
…On Sun, Sep 25, 2022 at 2:22 PM Glenn Jocher ***@***.***> wrote:
@jmiller-dr <https://github.com/jmiller-dr> just tested myself, crops
work correctly for me, I'm not able to reproduce any problem:
[image: Screenshot 2022-09-25 at 20 21 53]
<https://user-images.githubusercontent.com/26833433/192159102-33c4dae4-83b1-460e-9037-8479070ffd30.png>
—
Reply to this email directly, view it on GitHub
<#9585 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATR65F5EQDTDX5PIGBM57JDWACJ7BANCNFSM6AAAAAAQVFTQHY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
|
@jmiller-dr that's strange. If you can help us reproduce this in a common environment like a Colab notebook we could get started debugging it. What steps did you take to produce the bug? |
Edit: I posted here because I thought were no crops but they are in: runs/detect//crops. So in my case runs/detect/exp14/crops. I misremembered them into there being a general crops folder and overlooked it in the folder itself. |
👋 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 ⭐! |
@Denizzje no worries! It's great that you found the crops in the |
Search before asking
Question
I use
results.crop()
,results.crop(save=True)
, andpython3 yolov5/detect.py --save-crop --data 'myfile.yaml' --source 'images/train/*.jpeg' --weights 'yolov5/runs/train/exp22/weights/best.pt'
and it saves the images, but all of them are the exact same dimensions as the original. How do I crop and what are the options to
crop()
? I don't see any documentation of it, just a couple of references to it in the tutorials that don't seem to actually crop. Is there some undocumented margin parameter or something?Additional
No response
The text was updated successfully, but these errors were encountered: