Skip to content

Commit baf7e2a

Browse files
authored
Revise bird classifier setup and export process
Updated instructions for downloading and exporting the bird classifier model using ExecuTorch.
1 parent 480d9a2 commit baf7e2a

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

Yolo/android/README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@ Bird Detection Feature: Uses a two-stage pipeline where YOLO (COCO class 14) det
1414
Install dependencies
1515

1616
```
17-
pip install transformers torch pillow executorch
18-
Download EfficientNet bird classifier
19-
python -c "
20-
from transformers import AutoImageProcessor, AutoModelForImageClassification
21-
import torch
22-
model_name = 'dennisjooo/Birds-Classifier-EfficientNetB2'
23-
processor = AutoImageProcessor.from_pretrained(model_name)
24-
model = AutoModelForImageClassification.from_pretrained(model_name)
25-
model.save_pretrained('./bird_classifier_model')
26-
processor.save_pretrained('./bird_classifier_model')
27-
print('Bird classifier downloaded')
17+
import torch
18+
from transformers import AutoModelForImageClassification
19+
from torch.export import export
20+
from executorch.exir import to_edge_transform_and_lower
21+
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
22+
23+
# Download and load model
24+
model = AutoModelForImageClassification.from_pretrained("chriamue/bird-species-classifier")
25+
model.eval()
26+
27+
# Export to ExecuTorch
28+
example_input = torch.randn(1, 3, 224, 224)
29+
exported_program = export(model, (example_input,))
30+
edge_program = to_edge_transform_and_lower(
31+
exported_program,
32+
partitioner=[XnnpackPartitioner()]
33+
)
34+
et_program = edge_program.to_executorch()
35+
36+
# Save as .pte file
37+
with open("bird_classifier.pte", "wb") as f:
38+
et_program.write_to_file(f)
39+
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
2845
"
2946
```
3047

0 commit comments

Comments
 (0)