Coder Social home page Coder Social logo

Comments (5)

glenn-jocher avatar glenn-jocher commented on September 9, 2024

@xingguang12 hello! Thank you for bringing this issue to our attention. It's great to hear you're achieving good results with YOLOv5 on your verification and test sets. However, the discrepancy you're experiencing between detect.py and val.py results is indeed puzzling.

This issue typically stems from a few potential mismatches or misconfigurations between training time and inference time settings. Here are a few areas worth double-checking:

  1. Preprocessing Consistency: Ensure the preprocessing configurations (like image normalization, resizing) during detection match those used during training. This is crucial for maintaining model performance.
  2. Detection Thresholds: Although you've already adjusted conf_thres and iou_thres, it's worth experimenting further. Sometimes, extremely low thresholds can lead to unexpected behavior, including the suppression of all detections.
  3. Model Weights: Confirm you are using the correct final weights file from your training process. It's easy to accidentally use interim weights.
  4. Data Paths: Verify the paths provided to detect.py are correct and the images are accessible and properly formatted.

If these steps don't resolve the issue, it might require a deeper dive into specific configurations or potentially even model architecture considerations that are unique to your dataset.

Remember, the YOLO community and the Ultralytics team are here to support you. If persistent issues arise, please consider providing a minimal reproducible example that includes snippets of your dataset and the specific commands you're using. This can often illuminate overlooked discrepancies.

I hope this helps guide you towards resolving the discrepancy. Keep experimenting, and good luck! 👍

from yolov5.

xingguang12 avatar xingguang12 commented on September 9, 2024

The following is my environment,Yolov5 6.2 version is used.:
absl-py 0.13.0
anyio 3.3.1
argon2-cffi 21.1.0
attrs 21.2.0
Babel 2.9.1
backcall 0.2.0
bleach 4.1.0
brotlipy 0.7.0
cachetools 4.2.2
certifi 2021.5.30
cffi 1.14.6
chardet 4.0.0
conda 4.10.3
conda-package-handling 1.7.3
cryptography 3.4.7
cycler 0.10.0
debugpy 1.4.3
decorator 5.1.0
defusedxml 0.7.1
entrypoints 0.3
filelock 3.13.1
fsspec 2024.2.0
gitdb 4.0.11
GitPython 3.1.42
google-auth 1.35.0
google-auth-oauthlib 0.4.6
grpcio 1.40.0
huggingface-hub 0.21.3
idna 2.10
ipykernel 6.4.1
ipython 7.27.0
ipython-genutils 0.2.0
ipywidgets 7.6.5
jedi 0.18.0
Jinja2 3.0.1
json5 0.9.6
jsonschema 3.2.0
jupyter-client 7.0.3
jupyter-core 4.8.1
jupyter-server 1.11.0
jupyterlab 3.1.12
jupyterlab-language-pack-zh-CN 0.0.1.dev0
jupyterlab-pygments 0.1.2
jupyterlab-server 2.8.1
jupyterlab-widgets 1.0.2
kiwisolver 1.3.2
Markdown 3.3.4
MarkupSafe 2.0.1
matplotlib 3.4.3
matplotlib-inline 0.1.3
mistune 0.8.4
nbclassic 0.3.2
nbclient 0.5.4
nbconvert 6.1.0
nbformat 5.1.3
nest-asyncio 1.5.1
notebook 6.4.4
numpy 1.21.2
oauthlib 3.1.1
opencv-python 4.6.0.66
packaging 21.0
pandas 1.4.3
pandocfilters 1.5.0
parso 0.8.2
pexpect 4.8.0
pickleshare 0.7.5
Pillow 8.3.2
pip 21.1.3
prometheus-client 0.11.0
prompt-toolkit 3.0.20
protobuf 3.18.0
psutil 5.9.1
ptyprocess 0.7.0
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycocotools 2.0.4
pycosat 0.6.3
pycparser 2.20
Pygments 2.10.0
pyOpenSSL 20.0.1
pyparsing 2.4.7
pyrsistent 0.18.0
PySocks 1.7.1
python-dateutil 2.8.2
pytz 2021.1
PyYAML 6.0
pyzmq 22.3.0
requests 2.25.1
requests-oauthlib 1.3.0
requests-unixsocket 0.2.0
rsa 4.7.2
ruamel-yaml-conda 0.15.100
safetensors 0.4.2
scipy 1.8.1
seaborn 0.11.2
Send2Trash 1.8.0
setuptools 52.0.0.post20210125
six 1.16.0
smmap 5.0.1
sniffio 1.2.0
supervisor 4.2.2
tensorboard 2.6.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.0
terminado 0.12.1
testpath 0.5.0
thop 0.1.1.post2207130030
timm 0.9.16
torch 1.9.0+cu111
torchvision 0.10.0+cu111
tornado 6.1
tqdm 4.64.0
traitlets 5.1.0
typing-extensions 3.10.0.2
urllib3 1.26.6
wcwidth 0.2.5
webencodings 0.5.1
websocket-client 1.2.1
Werkzeug 2.0.1
wheel 0.36.2
widgetsnbextension 3.5.1
20240315210443

my dataset
https://drive.google.com/file/d/18-F-s_Ai840K5gtOGpb8SiNS4bh5PHJt/view?usp=drive_link

The following is the command I used in training. I used the trained best.pt as the weight of detect.py I tried many combinations of iou-thres and conf-thres, and only a few pictures were detected, which is very different from using val.py I don't know the reason at all. Please help me. Thank you very much.
python train.py --data rett100k.yaml --epochs 150 --weights yolov5s.pt --cfg yolov5s.yaml --batch-size 32 python val.py --task test --data rett100k.yaml --weights best.pt python detect.py --weights best.pt --source ../tt100k_v5_format_end/images/test

rett100k.yaml

path: ../tt100k_v5_format_end
train: images/train
val: images/val
test: images/test

nc: 45
names: ['pl80', 'p6', 'p5', 'pm55', 'pl60', 'ip', 'p11', 'i2r', 'p23', 'pg', 'il80', 'ph4', 'i4', 'pl70', 'pne', 'ph4.5', 'p12', 'p3', 'pl5', 'w13', 'i4l', 'pl30', 'p10', 'pn', 'w55', 'p26', 'p13', 'pr40', 'pl20', 'pm30', 'pl40', 'i2', 'pl120', 'w32', 'ph5', 'il60', 'w57', 'pl100', 'w59', 'il100', 'p19', 'pm20', 'i5', 'p27', 'pl50']

from yolov5.

xingguang12 avatar xingguang12 commented on September 9, 2024

import torch
import cv2

model = torch.hub.load('./', 'custom', './x.pt', source='local')

frame = cv2.imread('C:\my_create\python_code\detect/tt100k_2021\imgs/tt100k_v5_format_end\images/test/69135.jpg')
results = model(frame)
res = results.pandas().xyxy[0]
print(res)

Fusing layers...
YOLOv5s-p2-asf3_1 summary: 286 layers, 8429048 parameters, 0 gradients, 24.2 GFLOPs
Adding AutoShape...
xmin ymin xmax ymax confidence class name
0 1205.983276 809.077087 1242.669189 845.589355 0.895979 12 i4
1 1386.586426 1061.011108 1421.109497 1098.046265 0.894568 6 p11
2 1250.224976 811.186462 1282.181396 842.907166 0.868022 23 pn
3 584.543396 1049.830200 602.429626 1070.198975 0.582163 23 pn
4 1205.978027 808.952454 1243.837646 845.354004 0.546872 44 pl50
5 1206.409790 810.280762 1258.255127 845.607117 0.343998 23 pn

Process finished with exit code 0

when using detect.py
20240315224725

This is too strange, and it is getting more and more confusing. Using torch.hub.load and detect.py have completely different results. I need your help @glenn-jocher.

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 9, 2024

Hello @xingguang12! It looks like you're making good progress with your YOLOv5 model, but encountering some inconsistency between using torch.hub.load in your script and running detect.py. Let's clarify a potential cause for this.

One common reason for observing differences in detection results could be related to how images are loaded and preprocessed. The detect.py script performs specific preprocessing steps, including normalization and resizing, that might not exactly match what's happening when you load and process the image in your own script with OpenCV and torch.hub.load.

Ensure that your script accounts for the necessary preprocessing steps. Here’s a simplified example of adjusting your script to match the expected preprocessing:

import cv2
import torch

# Load your custom model
model = torch.hub.load('./', 'custom', './x.pt', source='local')

# Load your image with OpenCV
frame = cv2.imread('your_image_path.jpg')

# Convert BGR (OpenCV default) to RGB
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

# Resize image to model's expected size, for example 640x640
frame_resized = cv2.resize(frame_rgb, (640, 640))

# Convert to PyTorch tensor, normalize, and add batch dimension
frame_transformed = torch.from_numpy(frame_resized).float() / 255.0
frame_transformed = frame_transformed.permute((2, 0, 1)).unsqueeze(0)

# Run inference
results = model(frame_transformed)
res = results.pandas().xyxy[0]
print(res)

Note: Make sure the resize dimensions match your model's input size and consider any additional normalization that detect.py might perform.

If after ensuring consistent preprocessing you still notice discrepancies, it might be helpful to compare the exact versions of the dependencies (torch, torchvision, etc.) used in both approaches, as differences there could potentially affect results.

Keep exploring, and let us know how it goes!

from yolov5.

github-actions avatar github-actions commented on September 9, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

from yolov5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.