-
Notifications
You must be signed in to change notification settings - Fork 29
Clean up README.md, remove redundancies and fix code #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,17 +3,24 @@ | |||||
| ## 🐦 Android Bird Detection App with ExecuTorch | ||||||
|
|
||||||
| A real-time bird detection and species identification Android app using YOLO + EfficientNet models deployed via Meta's ExecuTorch framework. The app provides session-based bird watching with automatic logging, thumbnails, and timestamps for backyard bird enthusiasts. | ||||||
| Bird Detection Feature: Uses a two-stage pipeline where YOLO (COCO class 14) detects birds in camera frames, then EfficientNet classifier identifies the specific species from 525 possible bird types with 96.8% accuracy. | ||||||
|
|
||||||
| ## Model Download and Conversion | ||||||
|
|
||||||
| ### Step 1: Download Models | ||||||
| **Bird Detection Feature:** Uses a two-stage pipeline where YOLO (COCO class 14) detects birds in camera frames, then EfficientNet classifier identifies the specific species from 525 possible bird types with 96.8% accuracy. | ||||||
|
|
||||||
| #### Bird Classifier Model | ||||||
| ## Prerequisites | ||||||
|
|
||||||
| Install dependencies | ||||||
| Install required dependencies: | ||||||
|
|
||||||
| ```bash | ||||||
| pip install torch transformers executorch ultralytics | ||||||
| ``` | ||||||
|
|
||||||
| ## Model Download and Conversion | ||||||
|
|
||||||
| ### Step 1: Download and Convert Bird Classifier Model | ||||||
|
|
||||||
| Create `convert_bird_classifier.py`: | ||||||
|
|
||||||
| ```python | ||||||
| import torch | ||||||
| from transformers import AutoModelForImageClassification | ||||||
| from torch.export import export | ||||||
|
|
@@ -37,79 +44,41 @@ et_program = edge_program.to_executorch() | |||||
| with open("bird_classifier.pte", "wb") as f: | ||||||
| et_program.write_to_file(f) | ||||||
| print("Bird classifier converted to bird_classifier.pte") | ||||||
| ``` | ||||||
|
|
||||||
| Run it from a regular terminal (not Claude Code) to avoid the proxy block: | ||||||
| Run the script: | ||||||
|
|
||||||
| cd /home/sidart/executorch | ||||||
| ```bash | ||||||
| python convert_bird_classifier.py | ||||||
| " | ||||||
| ``` | ||||||
|
|
||||||
| ## Detection Model | ||||||
|
|
||||||
| The app supports both v8 and v26 and automatically detects which version you're using based on the model output format. | ||||||
| ### Step 2: Download YOLO Detection Model | ||||||
|
|
||||||
| Install Ultralytics: | ||||||
| The app supports both YOLOv8 and YOLOv26, and automatically detects which version you're using based on the model output format. | ||||||
|
|
||||||
| ``` | ||||||
| ```bash | ||||||
| pip install ultralytics | ||||||
| ``` | ||||||
|
|
||||||
| ### Download model | ||||||
|
|
||||||
| #### Option 1: v8 | ||||||
| python -c " | ||||||
| from ultralytics import | ||||||
| model = ('v8n.pt') # nano version for mobile | ||||||
| print('v8 model downloaded') | ||||||
| " | ||||||
| ``` | ||||||
|
|
||||||
| #### Option 2: v26 (Recommended - Faster & More Accurate) | ||||||
| python -c " | ||||||
| from ultralytics import | ||||||
| model = ('26n.pt') # nano version for mobile | ||||||
| print('v26 model downloaded') | ||||||
| " | ||||||
| #### Option 1: YOLOv8 | ||||||
| ```python | ||||||
| from ultralytics import YOLO | ||||||
| model = YOLO('yolov8n.pt') # nano version for mobile | ||||||
| print('YOLOv8 model downloaded') | ||||||
| ``` | ||||||
|
Comment on lines
+55
to
68
|
||||||
|
|
||||||
| ## Model Conversion to ExecuTorch | ||||||
|
|
||||||
| ### Step 2: Convert Models to .pte Format | ||||||
|
|
||||||
| #### Convert Bird Classifier | ||||||
|
|
||||||
| convert_bird_classifier.py | ||||||
|
|
||||||
| ``` | ||||||
| import torch | ||||||
| from transformers import AutoModelForImageClassification | ||||||
| from torch.export import export | ||||||
| from executorch.exir import to_edge_transform_and_lower | ||||||
| from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner | ||||||
| Load model | ||||||
| model = AutoModelForImageClassification.from_pretrained('./bird_classifier_model') | ||||||
| model.eval() | ||||||
| Export to ExecuTorch | ||||||
| example_input = torch.randn(1, 3, 224, 224) | ||||||
| exported_program = export(model, (example_input,)) | ||||||
| edge_program = to_edge_transform_and_lower( | ||||||
| exported_program, | ||||||
| partitioner=[XnnpackPartitioner()] | ||||||
| ) | ||||||
| et_program = edge_program.to_executorch() | ||||||
| Save as .pte file | ||||||
| with open("bird_classifier.pte", "wb") as f: | ||||||
| et_program.write_to_file(f) | ||||||
| print("Bird classifier converted to bird_classifier.pte") | ||||||
| #### Option 2: YOLOv26 (Recommended - Faster & More Accurate) | ||||||
| ```python | ||||||
| from ultralytics import YOLO | ||||||
| model = YOLO('yolo26n.pt') # nano version for mobile | ||||||
| print('YOLOv26 model downloaded') | ||||||
| ``` | ||||||
|
|
||||||
| ### Convert YOLO Model | ||||||
| ### Step 3: Convert YOLO Model to .pte Format | ||||||
|
|
||||||
| convert_yolo.py | ||||||
| This script works for both YOLOv8 and YOLOv26 - just change the model filename. | ||||||
| Create `convert_yolo.py`: | ||||||
|
|
||||||
| ``` | ||||||
| ```python | ||||||
| from ultralytics import YOLO | ||||||
| import torch | ||||||
| from torch.export import export | ||||||
|
|
@@ -137,25 +106,28 @@ with open("yolo_detector.pte", "wb") as f: | |||||
| print("YOLO model converted to yolo_detector.pte") | ||||||
| ``` | ||||||
|
|
||||||
| #### Auto-Detection: The app automatically detects which YOLO version you're using (v8 or v26) based on the model's output format. No code changes needed when switching between versions! | ||||||
| **Auto-Detection:** The app automatically detects which YOLO version you're using (v8 or v26) based on the model's output format. No code changes needed when switching between versions! | ||||||
|
|
||||||
| ### Generate Bird Species Names | ||||||
| ### Step 4: Generate Bird Species Names | ||||||
|
|
||||||
| extract_species_names.py | ||||||
| Create `extract_species_names.py`: | ||||||
|
|
||||||
| ``` | ||||||
| ```python | ||||||
| from transformers import AutoModelForImageClassification | ||||||
| import json | ||||||
|
|
||||||
| model = AutoModelForImageClassification.from_pretrained('./bird_classifier_model') | ||||||
|
||||||
| model = AutoModelForImageClassification.from_pretrained('./bird_classifier_model') | |
| model = AutoModelForImageClassification.from_pretrained("chriamue/bird-species-classifier") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pip install ultralyticsis listed both in Prerequisites and again in Step 2. To keep the flow concise and avoid redundancy, remove one of these (typically keep all installs in Prerequisites, and have Step 2 focus only on the download action).