-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
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
modify default value of stride to 64 in the function letterbox #13150
base: master
Are you sure you want to change the base?
Conversation
All Contributors have signed the CLA. ✅ |
I have read the CLA Document and I sign the CLA |
recheck |
@TommeyChang hello, Thank you for bringing this to our attention! To help us investigate the issue further, could you please provide a minimum reproducible code example? This will allow us to better understand the problem and work towards a solution. You can refer to our guidelines on creating a minimum reproducible example here: Minimum Reproducible Example. 🛠️ Additionally, please ensure that you are using the latest versions of Looking forward to your response so we can assist you further! |
When using the letterbox to resize an image of (1280, 1964, 3) into (1280, 1280) with stride=32, one dimension of the image is changed into 864. The example codes are: img = cv2.imread(img_path)
# check the size of original image
print(img_2_tensor.shape)
img_2_tensor = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_2_tensor = letterbox(img_2_tensor, new_shape=(1280, 1280), stride=32)[0]
# check the size of resized image
print(img_2_tensor.shape)
img_2_tensor = torch.from_numpy(img_2_tensor.transpose((2, 0, 1))).float().to(device) / 255.0
if img_2_tensor.ndimension() == 3:
img_2_tensor = img_2_tensor.unsqueeze(0)
pred = model(img_2_tensor)[0] |
Hello @TommeyChang, Thank you for providing a detailed description of the issue and the example code! This is very helpful. 😊 To address your concern, it seems like the error arises due to the mismatch in tensor sizes when the image is resized with a stride of 32. Changing the stride to 64 appears to resolve the issue in your case. Before we proceed further, could you please confirm the following:
If the issue persists after these checks, we can further investigate the possibility of modifying the default stride value or providing additional flexibility in the Thank you for your cooperation and for being an active member of the YOLO community! 🌟 |
Bug description: When the default value of stride is 32, it confronts an tensor size mismatch error when using letterbox to resize an image of (1280, 1964, 3) into (1280, 1280) with stride=32. MRE git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
import torch
import numpy as np
import cv2
from models.common import DetectMultiBackend
from utils.augmentations import letterbox
model_path = 'checkpoints/yolov5m6.pt'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DetectMultiBackend(model_path, device=device)
model.eval()
img = np.zeros((1280, 1964, 3), dtype=np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = letterbox(img, new_shape=(1280, 1280), stride=32)[0]
# check the size of resized image, (864, 1280, 3)
assert img.shape == (864, 1280, 3)
img_2_tensor = torch.from_numpy(img.transpose((2, 0, 1))).float().to(device) / 255.0
img_2_tensor = img_2_tensor.unsqueeze(0)
pred = model(img_2_tensor)[0] Error message:
Dependencies:
|
Hello @TommeyChang, Thank you for providing a detailed bug report and the minimum reproducible example (MRE). This is very helpful for diagnosing the issue. 😊 The tensor size mismatch error you're encountering when using
Thank you for your contribution and for being an active member of the YOLO community! If you have any further questions or need additional assistance, feel free to ask. 🌟 |
When the default value of stride is 32, it confronts an error when the width or height of the image is resized to 864.
I fix the bug from setting the stride to 64. Thus, I suggest to change the default value.
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Small update to the image preprocessing in YOLOv5 to allow more flexible stride options.
📊 Key Changes
letterbox
function'sstride
parameter from a default of32
to64
.🎯 Purpose & Impact
stride
value, images can be resized and padded with more flexible stride options.Overall, this change aims to optimize image preprocessing, benefiting both developers and end-users by making the model slightly more adaptable and efficient. 📈✨