Skip to content

Commit c947b03

Browse files
authored
Clean up README.md, remove redundancies and fix code (#229)
1 parent 4d0b9c6 commit c947b03

1 file changed

Lines changed: 55 additions & 96 deletions

File tree

Yolo/android/README.md

Lines changed: 55 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@
33
## 🐦 Android Bird Detection App with ExecuTorch
44

55
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.
6-
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.
76

8-
## Model Download and Conversion
7+
**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.
8+
9+
## Prerequisites
910

10-
### Step 1: Download Models
11+
Install PyTorch and ExecuTorch by following the [ExecuTorch installation guide](https://docs.pytorch.org/executorch/main/getting-started.html), which pins the compatible torch version. The simplest path is:
1112

12-
#### Bird Classifier Model
13+
```bash
14+
pip install executorch
15+
```
1316

14-
Install dependencies
17+
Then install the remaining dependencies:
1518

19+
```bash
20+
pip install transformers ultralytics
1621
```
22+
23+
For Android-specific setup, see the [Android section](https://docs.pytorch.org/executorch/main/android-section.html) of the ExecuTorch docs.
24+
25+
## Model Download and Conversion
26+
27+
### Step 1: Download and Convert Bird Classifier Model
28+
29+
Create `convert_bird_classifier.py`:
30+
31+
```python
1732
import torch
1833
from transformers import AutoModelForImageClassification
1934
from torch.export import export
@@ -37,79 +52,19 @@ et_program = edge_program.to_executorch()
3752
with open("bird_classifier.pte", "wb") as f:
3853
et_program.write_to_file(f)
3954
print("Bird classifier converted to bird_classifier.pte")
40-
41-
Run it from a regular terminal (not Claude Code) to avoid the proxy block:
42-
43-
cd /home/sidart/executorch
44-
python convert_bird_classifier.py
45-
"
4655
```
4756

48-
## Detection Model
49-
50-
The app supports both v8 and v26 and automatically detects which version you're using based on the model output format.
51-
52-
Install Ultralytics:
57+
Run the script:
5358

54-
```
55-
pip install ultralytics
56-
```
57-
58-
### Download model
59-
60-
#### Option 1: v8
61-
python -c "
62-
from ultralytics import
63-
model = ('v8n.pt') # nano version for mobile
64-
print('v8 model downloaded')
65-
"
66-
```
67-
68-
#### Option 2: v26 (Recommended - Faster & More Accurate)
69-
python -c "
70-
from ultralytics import
71-
model = ('26n.pt') # nano version for mobile
72-
print('v26 model downloaded')
73-
"
74-
```
75-
76-
## Model Conversion to ExecuTorch
77-
78-
### Step 2: Convert Models to .pte Format
79-
80-
#### Convert Bird Classifier
81-
82-
convert_bird_classifier.py
83-
84-
```
85-
import torch
86-
from transformers import AutoModelForImageClassification
87-
from torch.export import export
88-
from executorch.exir import to_edge_transform_and_lower
89-
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
90-
Load model
91-
model = AutoModelForImageClassification.from_pretrained('./bird_classifier_model')
92-
model.eval()
93-
Export to ExecuTorch
94-
example_input = torch.randn(1, 3, 224, 224)
95-
exported_program = export(model, (example_input,))
96-
edge_program = to_edge_transform_and_lower(
97-
exported_program,
98-
partitioner=[XnnpackPartitioner()]
99-
)
100-
et_program = edge_program.to_executorch()
101-
Save as .pte file
102-
with open("bird_classifier.pte", "wb") as f:
103-
et_program.write_to_file(f)
104-
print("Bird classifier converted to bird_classifier.pte")
59+
```bash
60+
python convert_bird_classifier.py
10561
```
10662

107-
### Convert YOLO Model
63+
### Step 2: Convert YOLO Model to .pte Format
10864

109-
convert_yolo.py
110-
This script works for both YOLOv8 and YOLOv26 - just change the model filename.
65+
Create `convert_yolo.py`:
11166

112-
```
67+
```python
11368
from ultralytics import YOLO
11469
import torch
11570
from torch.export import export
@@ -137,25 +92,28 @@ with open("yolo_detector.pte", "wb") as f:
13792
print("YOLO model converted to yolo_detector.pte")
13893
```
13994

140-
#### 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!
95+
**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!
14196

142-
### Generate Bird Species Names
97+
### Step 3: Generate Bird Species Names
14398

144-
extract_species_names.py
99+
Create `extract_species_names.py`:
145100

146-
```
101+
```python
147102
from transformers import AutoModelForImageClassification
148103
import json
149-
model = AutoModelForImageClassification.from_pretrained('./bird_classifier_model')
104+
105+
model = AutoModelForImageClassification.from_pretrained('chriamue/bird_classifier_model')
150106
species_names = [model.config.id2label[i] for i in range(len(model.config.id2label))]
107+
151108
with open('bird_species.json', 'w') as f:
152-
json.dump(species_names, f, indent=2)
109+
json.dump(species_names, f, indent=2)
110+
153111
print(f"Saved {len(species_names)} bird species names to bird_species.json")
154112
```
155113

156114
## Deploying Models to Android
157115

158-
### Step 3: Deploy Models to Android Device
116+
### Step 4: Deploy Models to Android Device
159117

160118
#### Copy Models to Android Assets
161119

@@ -166,57 +124,58 @@ cp yolo_detector.pte /path/to/android/app/src/main/assets/
166124
cp bird_species.json /path/to/android/app/src/main/assets/
167125
```
168126

169-
### Alternative: Push via ADB (for testing)
170-
171-
Connect Android device and enable USB debugging
127+
#### Alternative: Push via ADB (for testing)
172128

173-
```
129+
```bash
130+
# Connect Android device and enable USB debugging
174131
adb devices
175-
Create directory on device
132+
133+
# Create directory on device
176134
adb shell mkdir -p /data/local/tmp/bird_detection/
177-
Push model files
135+
136+
# Push model files
178137
adb push bird_classifier.pte /data/local/tmp/bird_detection/
179138
adb push yolo_detector.pte /data/local/tmp/bird_detection/
180139
adb push bird_species.json /data/local/tmp/bird_detection/
181-
Verify files are transferred
140+
141+
# Verify files are transferred
182142
adb shell ls -la /data/local/tmp/bird_detection/
183143
```
184144

185145
### File Structure
186146

187147
```
188148
app/src/main/assets/
189-
├── bird_classifier.pte # EfficientNet bird species classifier (8.5MB)
190-
├── yolo_detector.pte # YOLOv8n bird detection model (6MB)
191-
└── bird_species.json # List of 525 bird species names
149+
├── bird_classifier.pte # EfficientNet bird species classifier (~8.5MB)
150+
├── yolo_detector.pte # YOLO bird detection model (~6MB)
151+
└── bird_species.json # List of 525 bird species names
192152
```
193153

194154
## App Features
195155

196156
### Main Detection Screen
197157

198-
- Camera Preview: Real-time video feed from device camera
199-
- Live Detection: Green bounding boxes around detected birds with species labels
200-
- Session Controls: Start/Stop buttons for bird watching sessions
158+
- **Camera Preview:** Real-time video feed from device camera
159+
- **Live Detection:** Green bounding boxes around detected birds with species labels
160+
- **Session Controls:** Start/Stop buttons for bird watching sessions
201161

202162
### Session Management
203163

204-
#### "Start Session" Button:
205-
164+
**Start Session Button:**
206165
- Activates bird detection and logging
207166
- Changes camera from passive viewing to active detection mode
208167
- Begins collecting bird sightings with timestamps and thumbnails
209168
- Button turns red and displays "Stop Session"
210-
- "Stop Session" Button:
169+
170+
**Stop Session Button:**
211171
- Deactivates detection and shows session summary
212172
- Displays total birds detected and unique species count
213173
- Button turns green and displays "Start Session"
214174
- Preserves collected data for viewing
215175

216176
### Bird Log Viewer
217177

218-
#### "View Logs" Button:
219-
178+
**View Logs Button:**
220179
- Opens detailed session log showing all detected birds
221180
- Displays bird thumbnails, species names, detection times, and confidence scores
222181
- Organized as scrollable list with visual bird identification records

0 commit comments

Comments
 (0)