Closed fatejzz closed 2 years ago
👋 Hello @fatejzz, 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.
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
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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.
@fatejzz I'm sorry, we don't have resources to review custom code, but we have a few YOLOv5 C++ Inference examples on ONNX and OpenVINO exported models here:
YOLOv5 OpenCV DNN C++ inference on exported ONNX model examples:
YOLOv5 OpenVINO C++ inference examples:
See Export tutorial for details:
Good luck 🍀 and let us know if you have any other questions!
Hi @fatejzz , you can also refer following implementation, we rewrite it with OpenCV's C++ API .
float letterbox(
const cv::Mat& image,
cv::Mat& out_image,
const cv::Size& new_shape = cv::Size(640, 640),
int stride = 32,
const cv::Scalar& color = cv::Scalar(114, 114, 114),
bool fixed_shape = false,
bool scale_up = true) {
cv::Size shape = image.size();
float r = std::min(
(float)new_shape.height / (float)shape.height, (float)new_shape.width / (float)shape.width);
if (!scale_up) {
r = std::min(r, 1.0f);
}
int newUnpad[2]{
(int)std::round((float)shape.width * r), (int)std::round((float)shape.height * r)};
cv::Mat tmp;
if (shape.width != newUnpad[0] || shape.height != newUnpad[1]) {
cv::resize(image, tmp, cv::Size(newUnpad[0], newUnpad[1]));
} else {
tmp = image.clone();
}
float dw = new_shape.width - newUnpad[0];
float dh = new_shape.height - newUnpad[1];
if (!fixed_shape) {
dw = (float)((int)dw % stride);
dh = (float)((int)dh % stride);
}
dw /= 2.0f;
dh /= 2.0f;
int top = int(std::round(dh - 0.1f));
int bottom = int(std::round(dh + 0.1f));
int left = int(std::round(dw - 0.1f));
int right = int(std::round(dw + 0.1f));
cv::copyMakeBorder(tmp, out_image, top, bottom, left, right, cv::BORDER_CONSTANT, color);
return 1.0f / r;
}
@zhiqwang @glenn-jocher when I convert the input image into the tensor according to the image shape and input it into the model, there will be some errors like the above. But when I created the 640x640x3 tensor, the model could run.
I just quote the two codes, and it can work well until now. but the 'letterbox' has some differences in mechanisms from others.
padd_w=padd_w%64; padd_h=padd_h%64;
@glenn-jocher After discussing it with others, I am wondering whether it is because when I use torchscript to export the model, the model's input size has been limited like [640,640].
@fatejzz yes, most exports require fixed input sizes. I think only PyTorch and ONNX --dynamic support dynamic input sizes.
👋 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 ⭐!
Search before asking
Question
At present, I am trying to deploy my Yolo model in ros. And I use c++ for my Yolo model to make predictions. However, it doesn't work well. Given the same image, when I use detect.py it can make correct predictions. But when I use my code it can't predict well for the existing wrong box. I think it is because of the image preprocessing process, I imitate the letterbox in detect.py, but it will meet a problem.
File "code/torch/models/yolo.py", line 71, in forward _35 = (_20).forward(_34, ) _36 = (_22).forward((_21).forward(_35, ), _29, ) _37 = (_24).forward(_33, _35, (_23).forward(_36, ), )