This project integrates Google’s SpeciesNet for wildlife classification with a weapon detection model (ONNX Runtime) and a real-time MQTT sensor dashboard to monitor remote field cameras, detect threats, and trigger instant Telegram alerts.
- AI Image & Video Analysis: Real-time local inference using SpeciesNet for wildlife classification and weapon detection for identifying armed threats.
- Hybrid GPU–CPU Architecture: Wildlife classification runs on NVIDIA RTX GPUs via PyTorch (CUDA), while weapon detection operates on the CPU using ONNX Runtime for efficient asymmetric processing.
- IoT Sensor Dashboard: Real-time monitoring of remote field units (Motion, Tilt, Gunshot, and System Status) through an MQTT broker with live device health tracking.
- Telegram Alerts: Automated push notifications with species name, confidence score, timestamps, and threat classification , including cooldown logic to prevent alert spam.
Before installing, ensure your Windows machine has the following:
- Python 3.10.11: Download Python (Make sure to check "Add Python to PATH" during installation).
- NVIDIA GPU Drivers: Required for hardware acceleration.
- Eclipse Mosquitto: Download Mosquitto for Windows. This is the MQTT broker that allows your ESP32 to talk to the Python server. Install it and ensure the "Mosquitto Broker" service is running in Windows Services.
(Note: You must add "listener 1883 0.0.0.0" "allow_anonymous true" at the end of mosquitto.conf file).
Keep your dependencies isolated by creating a virtual environment:
py -3.10 -m venv venv
.\venv\Scripts\activate
(Note: You must run .\venv\Scripts\activate every time you open a new terminal to work on this project).
NVIDIA GPU (CUDA 11.8)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
Install everything by running:
pip install -r requirements.txtThe SpeciesNet AI model is a ~200MB file that must be downloaded.
- Go to Kaggle: SpeciesNet v4.0.2a PyTorch Model
- Download the
archive.tar.gzfile and extract it. - Open the extracted folder. Move all of its contents directly into your project's
speciesnet_model/folder.
⚠️ Rule: The fileinfo.jsonMUST be located exactly atWildlifeProject\speciesnet_model\info.json. Do not leave it nested inside an "archive" subfolder.
Create a hidden environment file to securely store your API keys.
- Create a file named exactly
.envin your main project folder. - Add your credentials to the file:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHAT_ID=your_chat_id_here
ROBOFLOW_API_KEY=your_api_keyBefore running the server, verify your project folder looks exactly like this:
WildlifeProject/
│
├── app.py # Main backend server & AI logic
├── requirements.txt # Python dependencies list
├── .env # Hidden file for Telegram API keys
├── species_data.db # SQLite database for detection history
│
├── speciesnet_model/ # The downloaded Kaggle AI model
│ ├── always_crop_... .pt # PyTorch model weights
│ └── info.json # Model configuration
│
├── templates/ # Frontend HTML UI
│ ├── index.html
│ ├── sensor.html
│ └── amb82_dashboard.html
│
├── static/
│ └── detections/ # Where AI-cropped animal images are saved
│
├── uploads/
│ └── videos/ # Temporary storage for video processing
│
├── temp_inference/
│ └── frames/ # Temporary frame extraction folder
│
└── venv/ # Virtual environment
- Ensure your Mosquitto MQTT broker is running in the background at port:1883 and host:127.0.0.1
- Open your terminal, activate your virtual environment, and run:
python app.py
- Wait for Warmup: The first time you launch, it will take 1-3 minutes to load the PyTorch model into your GPU's VRAM. Wait until you see
🌐 LOCAL URL: http://127.0.0.1:5000in the console. - Open your web browser and navigate to:
- Dashboard:
http://127.0.0.1:5000/field_unit
- Server is running, but the browser says "Site cannot be reached" (HTTP 404/Refused): Windows Defender Firewall is likely blocking Python. Restart the server and check BOTH "Private" and "Public" networks on the Windows defender .
- Model Load Error:
No such file or directory 'info.json': Your Kaggle model files are extracted into a subfolder. Move them out of thearchivefolder directly intospeciesnet_model.* MQTT Connection Error: Ensure Mosquitto is installed and the Windows Service is actively running. The script attempts to connect to127.0.0.1on port1883.