brand-eye / README.md
haydarkadioglu's picture
Update README.md
89fa2b0 verified
---
license: apache-2.0
language:
- en
metrics:
- recall
base_model:
- Ultralytics/YOLOv8
pipeline_tag: object-detection
tags:
- object_detection
- computer-vision
- yolo
- brand-detection
- logo-detection
datasets:
- haydarkadioglu/brand-eye-dataset
---
# πŸ” Brand Eye - YOLO Brand Detection Model
A powerful YOLO-based object detection model specifically trained for brand and logo recognition tasks.
## 🌟 Overview
Brand Eye is a state-of-the-art computer vision model that can detect and classify various brands and logos in images. Built on the YOLO (You Only Look Once) architecture, it provides fast and accurate real-time brand detection capabilities.
## πŸ“Š Model Performance
- **Training Epochs**: 50
- **Best mAP@0.5**: 0.825+ (See training results)
- **Best mAP@0.5:0.95**: 0.494+ (See training results)
- **Architecture**: YOLOv5/YOLOv8 Custom
- **Input Size**: 640x640
- **Model Size**: ~14MB (optimized)
### πŸ“ˆ Training Metrics
![Training Metrics](images/metrics.png)
### 🎯 Model Accuracy
![Confusion Matrix](images/confusion_matrix_normalized.png)
### πŸ“‹ Validation Examples
| Ground Truth Labels | Model Predictions |
|:-------------------:|:-----------------:|
| ![Labels](images/val_batch0_labels.jpg) | ![Predictions](images/val_batch0_pred.jpg) |
| *Ground truth annotations* | *Model predictions with confidence scores* |
## 🎬 Demo Results
See the model in action! The images above show:
- **Training Metrics**: Comprehensive performance charts showing loss curves, precision, recall, and mAP scores over 50 epochs
- **Confusion Matrix**: Normalized confusion matrix displaying model accuracy across different brand classes
- **Validation Examples**: Side-by-side comparison of ground truth labels vs. model predictions on validation data
The model demonstrates excellent performance with:
- βœ… High precision in brand detection
- βœ… Strong recall across different brand categories
- βœ… Accurate bounding box predictions
- βœ… Reliable confidence scoring
## πŸš€ Quick Start
### Installation
```bash
pip install ultralytics huggingface_hub torch torchvision opencv-python pillow
```
### Download Model from Hugging Face
```python
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
# Download the trained model
model_path = hf_hub_download(
repo_id="haydarkadioglu/brand-eye",
filename="brandeye.pt"
)
# Load the model
model = YOLO(model_path)
```
### Basic Usage
#### Single Image Detection
```python
import cv2
from PIL import Image
def detect_brands(image_path, conf_threshold=0.25):
"""
Detect brands in a single image
Args:
image_path (str): Path to the image file
conf_threshold (float): Confidence threshold (0.0-1.0)
Returns:
results: Detection results with bounding boxes and labels
"""
results = model(image_path, conf=conf_threshold)
# Display results
results[0].show()
# Get detection details
boxes = results[0].boxes
if boxes is not None:
print(f"Found {len(boxes)} brand detections:")
for box in boxes:
conf = box.conf[0].item()
cls = int(box.cls[0].item())
class_name = model.names[cls]
print(f" - {class_name}: {conf:.3f} confidence")
return results
# Example usage
results = detect_brands("path/to/your/image.jpg")
```
#### Batch Processing
```python
import os
from pathlib import Path
def process_folder(input_folder, output_folder="results", conf=0.25):
"""
Process all images in a folder
Args:
input_folder (str): Path to folder containing images
output_folder (str): Path to save results
conf (float): Confidence threshold
"""
input_path = Path(input_folder)
output_path = Path(output_folder)
output_path.mkdir(exist_ok=True)
# Supported image formats
image_extensions = ['.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.webp']
for img_file in input_path.iterdir():
if img_file.suffix.lower() in image_extensions:
print(f"Processing {img_file.name}...")
# Run detection
results = model(str(img_file), conf=conf)
# Save annotated image
save_path = output_path / f"detected_{img_file.name}"
results[0].save(str(save_path))
# Print summary
boxes = results[0].boxes
if boxes is not None:
print(f" βœ… Found {len(boxes)} brands")
else:
print(f" ❌ No brands detected")
# Example usage
process_folder("input_images/", "detection_results/")
```
#### Real-time Detection (Webcam)
```python
import cv2
def real_time_detection():
"""
Real-time brand detection using webcam
"""
cap = cv2.VideoCapture(0) # Use 0 for default camera
while True:
ret, frame = cap.read()
if not ret:
break
# Run detection
results = model(frame, conf=0.3)
# Draw results on frame
annotated_frame = results[0].plot()
# Display frame
cv2.imshow('Brand Detection', annotated_frame)
# Exit on 'q' press
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
# Run real-time detection
# real_time_detection()
```
## πŸ“ Project Structure
```
brand-eye/
β”œβ”€β”€ README.md # This file
β”œβ”€β”€ visualize.ipynb # Training results visualization
β”œβ”€β”€ brandeye.pt # Trained model weights
β”œβ”€β”€ model/
β”‚ β”œβ”€β”€ train/
β”‚ β”‚ β”œβ”€β”€ results.csv # Training metrics
β”‚ β”‚ β”œβ”€β”€ weights/
β”‚ β”‚ β”‚ └── last.pt # Final model checkpoint
β”‚ β”‚ └── *.png # Training plots
β”‚ └── val/
β”‚ β”œβ”€β”€ predictions.json # Validation predictions
β”‚ └── *.png # Validation visualizations
β”œβ”€β”€ confusion_matrix_normalized.png # Model confusion matrix
└── val_batch*_*.jpg # Validation batch examples
```
## 🎯 Use Cases
- **Brand Monitoring**: Track brand presence in social media images
- **Market Research**: Analyze brand visibility in retail environments
- **Advertising Analysis**: Measure brand exposure in marketing materials
- **Quality Control**: Verify proper brand logo placement
- **Content Moderation**: Detect unauthorized brand usage
## πŸ”§ Advanced Usage
### Custom Confidence Thresholds
```python
# High precision (fewer false positives)
results_high_conf = model("image.jpg", conf=0.7)
# High recall (catch more brands, may include false positives)
results_low_conf = model("image.jpg", conf=0.1)
```
### Export to Different Formats
```python
# Export detections to JSON
import json
def export_detections(image_path, output_json):
results = model(image_path)
detections = []
boxes = results[0].boxes
if boxes is not None:
for box in boxes:
detection = {
"class": model.names[int(box.cls[0])],
"confidence": float(box.conf[0]),
"bbox": box.xyxy[0].tolist() # [x1, y1, x2, y2]
}
detections.append(detection)
with open(output_json, 'w') as f:
json.dump(detections, f, indent=2)
export_detections("image.jpg", "detections.json")
```
## 🀝 Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## πŸ“„ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## πŸ“ž Contact
- **Project**: [GitHub Repository](https://github.com/haydarkadioglu/brand-eye)
- **Model**: [Hugging Face Model](https://huggingface.co/haydarkadioglu/brand-eye)
- **Issues**: [GitHub Issues](https://github.com/haydarkadioglu/brand-eye/issues)
---
**Made with ❀️ for brand detection**