This repository contains scripts and notebooks to build a model that can classify tigers (and other species) in camera trap images, using ML (e. g. MegaDetector and MEWC), open source tools and data (e. g. LILA BC) and free compute resources (i. e. Colab and Kaggle).
Credentials: LILA BC, MegaDetector, own illustration.
- tigers are an endangered species, NGOs like the Nepal Tiger Trust protect them
- there is no open and easy way for ecologists/researchers/NGOs to classify their camera trap images with regard to tigers
- ML and open data/tools can help reduce the amount of manual labor when sifting through large amounts of camera trap images, looking for the needle in the haystack
- goal: train a species classifier for Nepal (focussing on tigers) and make it available through EcoAssist
Data sources
Sample and download images
- Download image URLs and labels from LILA BC
- For each selected species: sample and download images, create train test split if applicable
- Copy images to Drive
Note: Since Colab and Drive have limited capacities, one might have to further split up the process. Note: I found the image downloading to be much faster in Colab and Drive compared to Kaggle.
Preprocess images
- Run MegaDetector on all images
- Snip images following mewc-snip
- Copy snipped images to Kaggle Output
Note: Images must have been previously downloaded to Drive via Colab and then uploaded to Kaggle (zipped folder). Note: I found access to free GPUs much better and transparent in Kaggle compared to Colab.
- Use Keras Image Models
- Follow mewc-train
- Log experiments using Weights & Biases
I selected a pre-trained EfficientNetV2S with 21 mio parameters because it constitutes a good compromise between predictive performance, training time and model size. The model has been trained for 30 epochs (early stopping after 24 epochs) with 4000 images per class. The model has been evaluated on 300 images per class. Below is the resulting confusion matrix.
Other metrics can be found in the respective experiment run on Weights & Biases.
Note: There are only ~300 tiger images on LILA BC. I didn't use them in training but instead put all of them in test2
to examine how the model would potentially generalize to tiger camera trap images from another source than the tiger training images
(like it would be the case with the Nepal Tiger Trust using the model on their own images through EcoAssist).
- Publish model on HuggingFace
- Integrate and use model in EcoAssist
Join AI for Conservation Slack and WILDLABS if you're interested in using technology for conservation.
Feel free to reach out if you have feedback/ideas or would like to contribute/collaborate!