Skip to content

Repository files navigation

Car Part Recognizer & Detector

This project combines classification (ResNet50) and detection (YOLOv8) for comprehensive car part recognition.

Two Pipelines

Pipeline 1: Classification (ResNet50 + Ontology)

For single-class image classification with ontology enrichment.

Install dependencies:

pip install -r requirements.txt

Prepare a model file:

python prepare_model.py --train-dir train --out models/resnet50_pretrained_head.pt

Train classifier:

python train.py --train-dir train --val-dir valid --epochs 10 --batch-size 32 --out models/best_model.pt

Infer (top-5 predictions with category):

python infer.py path/to/image.jpg --model models/best_model.pt --topk 5

Pipeline 2: Detection (YOLOv8 + Multi-Label)

For detecting multiple car parts in a single image with bounding boxes.

Step 1: Generate Pseudo-Labels (Weak Supervision)

If you don't have manual bounding-box annotations, use Class Activation Maps (CAM) to auto-generate them:

python weak_supervision.py --train-dir train --output datasets/detection

This creates a YOLO-format dataset in datasets/detection/ with:

  • images/ - all images from train/
  • labels/ - YOLO format bounding boxes (class_id cx cy w h)

Optional: If you have manual YOLO annotations already, organize them as:

datasets/detection/
  images/
    image1.jpg
    image2.jpg
    ...
  labels/
    image1.txt
    image2.txt
    ...

Step 2: Train YOLOv8

python yolo_train.py --dataset datasets/detection --epochs 50 --batch-size 16 --model m

Parameters:

  • --model: n (nano), s (small), m (medium), l (large), x (xlarge) - trade-off between speed and accuracy
  • --epochs: training epochs (50-100 recommended)
  • --batch-size: batch size (adjust based on GPU memory)
  • --device: GPU device id or 'cpu'

Training outputs are saved to runs/detect/car_parts/

Step 3: Infer with Detection

Run detection on a single image:

python yolo_infer.py path/to/image.jpg --model runs/detect/car_parts/weights/best.pt --topk 10 --visualize

Parameters:

  • --conf: confidence threshold (0.0-1.0, default 0.5)
  • --iou: NMS IOU threshold (default 0.45)
  • --topk: return top-K detections
  • --visualize: save annotated image to detection_output.jpg

Output: For each detected part:

  • Bounding box (pixel and normalized coordinates)
  • Class name and confidence
  • Ontology category and synonyms

Dataset Structure

train/
  AIR COMPRESSOR/
    img1.jpg
    img2.jpg
  ALTERNATOR/
    img1.jpg
    ...
valid/
  AIR COMPRESSOR/
    img1.jpg
  ...

Features

  • Ontology Integration: All 50 car parts organized into 18 semantic categories (Engine, Brakes, Electrical, etc.)
  • Multi-Part Detection: YOLOv8 detects multiple parts per image with bounding boxes
  • Weak Supervision: Auto-generate pseudo-labels from single-class images using CAM
  • Mixed Precision Training: Faster training with FP16
  • Scheduled Learning Rate: Adaptive LR reduction on validation plateau
  • Class Weighting: Handles imbalanced datasets

Next Steps to Production

  1. Annotate manually (optional): Use tools like Roboflow or Label Studio for high-quality bounding boxes.
  2. Ensemble: Train multiple YOLOv8 sizes and average predictions.
  3. Fine-tune on edge: Convert to ONNX/TensorRT for deployment on mobile/edge devices.
  4. Monitor: Log metrics to WandB or TensorBoard.

Notes

  • Classification (infer.py) treats each image as containing one part type.
  • Detection (yolo_infer.py) finds all parts in an image—use this for real-world scenarios.
  • Ontology (ontology.json) maps part names to categories and synonyms for intelligent recognition.

About

This project combines deep learning–based classification (ResNet50) and real-time detection (YOLOv8) to identify and localize car parts with high accuracy.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages