Closed Raghucharan16 closed 1 month ago
π Hello @Raghucharan16, 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 a minimum reproducible example to help us debug it.
If this is a custom training β Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.
Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. 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, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.
We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 π!
Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.
Check out our YOLOv8 Docs for details and get started with:
pip install ultralytics
@Raghucharan16 hello,
Thank you for your detailed report and for providing the minimal reproducible example. This is very helpful! Let's work through this issue together.
Ensure Latest Versions: First, please make sure you are using the latest versions of torch
and YOLOv5. You can update them using the following commands:
pip install --upgrade torch
pip install --upgrade git+https://github.com/ultralytics/yolov5.git
Reproduce the Issue: If the issue persists after updating, we need to ensure that we can reproduce it. The code snippet you provided is quite comprehensive, but it would be helpful to have the exact version of the YOLO model you are using (YOLOv5s
, YOLOv5m
, etc.) and any specific configurations or weights you have applied.
Model Confidence Threshold: Sometimes, adjusting the confidence threshold can help in detecting faces more accurately. You can try lowering the confidence_threshold
parameter in your upscale_faces_with_boxes
function to see if it improves detection for single-face images.
Image Preprocessing: Ensure that the input images are preprocessed correctly. Sometimes, resizing or normalizing the images before feeding them into the model can improve detection accuracy.
Bounding Box Post-Processing: Verify the bounding box coordinates and ensure they are within the image dimensions. Sometimes, incorrect bounding box values can lead to false positives or missed detections.
Here's an example of how you might adjust the confidence threshold and add some preprocessing steps:
import os
import logging
import cv2
from PIL import Image, ImageDraw
import numpy as np
def upscale_faces_with_boxes(input_image_path, output_image_path, a, confidence_threshold=0.3):
# Read the input image
img = cv2.imread(input_image_path)
if img is None:
logging.error(f"Could not read image {input_image_path}")
return
# Preprocess the image (resize and normalize)
img_resized = cv2.resize(img, (640, 640))
img_normalized = img_resized / 255.0
# Detect faces using YOLO
bounding_boxes = a.predict(img_normalized)[0]
logging.info('facial features: %s', bounding_boxes)
# Load the original image using PIL
original_image = Image.open(input_image_path)
if original_image.mode == 'RGBA':
original_image = original_image.convert('RGB')
# Draw bounding boxes on the original image
draw = ImageDraw.Draw(original_image)
for bbox_group in bounding_boxes:
for bbox in bbox_group:
if bbox[4] >= confidence_threshold: # Check confidence score
left, top, right, bottom = bbox[:4]
draw.rectangle([left, top, right, bottom], outline="red", width=3)
# Save the image with bounding boxes
original_image.save(output_image_path)
logging.info(f"Image with bounding boxes saved to {output_image_path}")
input_image_path = 'IMG_20240613_165627217.jpg'
output_image_path = 'outputfolder/image_with_boxes.jpg'
from yoloface_master.YOLOFaceDetector import YoloDetector
a = YoloDetector()
upscale_faces_with_boxes(input_image_path, output_image_path, a)
If the issue persists, please provide more details about the specific YOLO model and weights you are using. This will help us further diagnose the problem.
Thank you for your patience and cooperation. The YOLO community and the Ultralytics team are here to help!
Hey @glenn-jocher Thanks for the response, I'll try with adjusting threshold and let you know the results.
Hello @Raghucharan16,
Thank you for your prompt response! Adjusting the confidence threshold is a great first step. It can often help in fine-tuning the model's sensitivity to detect faces more accurately.
Adjust Confidence Threshold: As mentioned, try lowering the confidence threshold in your detection function. This can help the model pick up on faces that it might otherwise miss.
Update Packages: Ensure you are using the latest versions of torch
and YOLOv5. This can be done with the following commands:
pip install --upgrade torch
pip install --upgrade git+https://github.com/ultralytics/yolov5.git
Image Preprocessing: Consider adding preprocessing steps like resizing and normalizing the input images. This can sometimes improve detection accuracy.
Here's a quick example of how you might adjust the confidence threshold and add some preprocessing steps:
import os
import logging
import cv2
from PIL import Image, ImageDraw
import numpy as np
def upscale_faces_with_boxes(input_image_path, output_image_path, a, confidence_threshold=0.3):
# Read the input image
img = cv2.imread(input_image_path)
if img is None:
logging.error(f"Could not read image {input_image_path}")
return
# Preprocess the image (resize and normalize)
img_resized = cv2.resize(img, (640, 640))
img_normalized = img_resized / 255.0
# Detect faces using YOLO
bounding_boxes = a.predict(img_normalized)[0]
logging.info('facial features: %s', bounding_boxes)
# Load the original image using PIL
original_image = Image.open(input_image_path)
if original_image.mode == 'RGBA':
original_image = original_image.convert('RGB')
# Draw bounding boxes on the original image
draw = ImageDraw.Draw(original_image)
for bbox_group in bounding_boxes:
for bbox in bbox_group:
if bbox[4] >= confidence_threshold: # Check confidence score
left, top, right, bottom = bbox[:4]
draw.rectangle([left, top, right, bottom], outline="red", width=3)
# Save the image with bounding boxes
original_image.save(output_image_path)
logging.info(f"Image with bounding boxes saved to {output_image_path}")
input_image_path = 'IMG_20240613_165627217.jpg'
output_image_path = 'outputfolder/image_with_boxes.jpg'
from yoloface_master.YOLOFaceDetector import YoloDetector
a = YoloDetector()
upscale_faces_with_boxes(input_image_path, output_image_path, a)
For further assistance, you can refer to our YOLOv5 documentation which provides comprehensive guides and examples.
Please let us know how it goes after making these adjustments. If the issue persists, feel free to share any additional details or outputs. The YOLO community and the Ultralytics team are here to support you!
Hey @glenn-jocher This is the repo i refered to for yolov5 face detection. and i tried adjusting the threshold as above and also tried lowering to 0.1 and results are same. like the same picture is getting saved without bounding boxes.
Hello @Raghucharan16,
Thank you for sharing the repository link and for trying the suggested adjustments. I appreciate your efforts in troubleshooting the issue.
Minimum Reproducible Example: To help us better understand and reproduce the issue, could you please provide a minimal reproducible code example? This will enable us to investigate the problem more effectively. You can refer to our guide on creating a minimum reproducible example for more details.
Ensure Latest Versions: Please verify that you are using the latest versions of torch
and YOLOv5. You can update them using the following commands:
pip install --upgrade torch
pip install --upgrade git+https://github.com/ultralytics/yolov5.git
Model Weights: Ensure that you are using the correct model weights for face detection. Sometimes, using pre-trained weights specifically fine-tuned for face detection can yield better results.
Debugging Output: Add some debugging output to check the bounding boxes and confidence scores returned by the model. This can help identify if the issue lies in the detection step or the post-processing step.
Hereβs an example of how you might add debugging output:
import os
import logging
import cv2
from PIL import Image, ImageDraw
import numpy as np
def upscale_faces_with_boxes(input_image_path, output_image_path, a, confidence_threshold=0.3):
# Read the input image
img = cv2.imread(input_image_path)
if img is None:
logging.error(f"Could not read image {input_image_path}")
return
# Preprocess the image (resize and normalize)
img_resized = cv2.resize(img, (640, 640))
img_normalized = img_resized / 255.0
# Detect faces using YOLO
bounding_boxes = a.predict(img_normalized)[0]
logging.info('facial features: %s', bounding_boxes)
# Debugging output
print(f"Detected bounding boxes: {bounding_boxes}")
# Load the original image using PIL
original_image = Image.open(input_image_path)
if original_image.mode == 'RGBA':
original_image = original_image.convert('RGB')
# Draw bounding boxes on the original image
draw = ImageDraw.Draw(original_image)
for bbox_group in bounding_boxes:
for bbox in bbox_group:
if bbox[4] >= confidence_threshold: # Check confidence score
left, top, right, bottom = bbox[:4]
draw.rectangle([left, top, right, bottom], outline="red", width=3)
# Save the image with bounding boxes
original_image.save(output_image_path)
logging.info(f"Image with bounding boxes saved to {output_image_path}")
input_image_path = 'IMG_20240613_165627217.jpg'
output_image_path = 'outputfolder/image_with_boxes.jpg'
from yoloface_master.YOLOFaceDetector import YoloDetector
a = YoloDetector()
upscale_faces_with_boxes(input_image_path, output_image_path, a)
The YOLO community and the Ultralytics team are here to support you. If you continue to experience issues, please provide the requested details, and we'll do our best to assist you further.
Thank you for your patience and cooperation!
π 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 β
Search before asking
YOLOv5 Component
Detection
Bug
I know this sound silly but I'm stuck at face detection using yolov5. The algorithm works fine for some images with multiple faces with great accuracy. but if we feed single face images, [only one face in image it is not detecting the face and also giving false positive which is not a face. [for another person's face image, i got this image as output]
here are the examples;
Input Image:
Output Image for code below:
Is there any processing is to be done to image? and in result you can see rotated image given by yolo. and below is another example which it perfectly works with same code.
Input Image:
Output Image:
Environment
Minimal Reproducible Example
Additional
It is not working with single faced images and i tried a lot by adjusting parameters in yolo detector initialiser. is there a fix for this??
Are you willing to submit a PR?