|
|
--- |
|
|
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 |
|
|
|
|
|
 |
|
|
|
|
|
### π― Model Accuracy |
|
|
|
|
|
 |
|
|
|
|
|
### π Validation Examples |
|
|
|
|
|
| Ground Truth Labels | Model Predictions | |
|
|
|:-------------------:|:-----------------:| |
|
|
|  |  | |
|
|
| *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** |