This guide will get you up and running with the Real-time Anomaly Detection system in minutes.
# Check Python version (need 3.9+)
python --version
# Check if CUDA is available (optional, for GPU training)
python -c "import torch; print(f'CUDA Available: {torch.cuda.is_available()}')"# 1. Clone repository (or navigate to project)
cd "d:\Upload Projects\AI projects\Real-time Anomaly Detection on Edge via Quantized DL"
# 2. Create virtual environment
python -m venv venv
# 3. Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
# source venv/bin/activate
# 4. Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# 5. Install package
pip install -e .# 1. Generate synthetic training data (2-3 minutes)
python scripts\generate_synthetic_data.py
# 2. Train model (10-20 minutes on GPU, longer on CPU)
python train.py
# 3. Evaluate model
python evaluate.py --checkpoint checkpoints\best_model.ckpt# 1. Download CWRU dataset (automatic on first run)
python scripts\download_dataset.py
# 2. Train model
python train.py --config config\config.yaml
# 3. Calculate optimal threshold
python scripts\calculate_threshold.py --checkpoint checkpoints\best_model.ckpt
# 4. Evaluate
python evaluate.py --checkpoint checkpoints\best_model.ckpt# 1. Export model
python export_onnx.py --checkpoint checkpoints\best_model.ckpt --output exports\model.onnx
# 2. Test inference
python inference.py --model exports\model.onnx --backend onnx --input data\test_sample.npy# Start API server
$env:MODEL_PATH="exports\model.onnx"
$env:BACKEND="onnx"
$env:THRESHOLD="0.1"
python api\app.py
# In another terminal, test API:
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" -d "{\"features\": [0.1, ...]}"
# Or visit http://localhost:8000/docs for interactive API documentation# Build image
docker build -t edge-anomaly-detection:latest .
# Run container
docker run -d --name anomaly-api -p 8000:8000 edge-anomaly-detection:latest
# Or use docker-compose (includes monitoring)
docker-compose up -d
# Access services:
# - API: http://localhost:8000
# - Prometheus: http://localhost:9090
# - Grafana: http://localhost:3000 (admin/admin)# Basic training
python train.py
# Resume from checkpoint
python train.py --resume checkpoints\last.ckpt
# Custom configuration
python train.py --config config\custom_config.yaml
# Enable quantization-aware training
python train.py --qat# Post-Training Quantization (PTQ)
python quantize_ptq.py --checkpoint checkpoints\best_model.ckpt
# Export quantized model to ONNX
python export_onnx.py --checkpoint checkpoints\quantized_ptq.ckpt# PyTorch inference
python inference.py --model checkpoints\best_model.ckpt --backend pytorch --input data\test.npy
# ONNX inference (faster)
python inference.py --model exports\model.onnx --backend onnx --input data\test.npy
# TensorRT inference (fastest, NVIDIA only)
python export_tensorrt.py --onnx exports\model.onnx --fp16
python inference.py --model exports\model.engine --backend tensorrt --input data\test.npy# View training logs
tensorboard --logdir logs\tensorboard
# Check Prometheus metrics
curl http://localhost:8000/metrics
# View Grafana dashboards
# Open http://localhost:3000
# Default credentials: admin/admin# Reduce batch size in config/config.yaml
training:
batch_size: 128 # Default is 256# Enable mixed precision training (already enabled by default)
training:
use_amp: true
amp_dtype: "float16"# Reinstall package
pip install -e .# Check if model path is correct
echo $env:MODEL_PATH # Windows
# echo $MODEL_PATH # Linux/Mac
# Check logs
docker logs anomaly-api📁 Key Files:
├── train.py # Main training script
├── inference.py # Inference script (all backends)
├── evaluate.py # Model evaluation
├── export_onnx.py # ONNX export
├── export_tensorrt.py # TensorRT export
├── quantize_ptq.py # Post-training quantization
├── docker-compose.yml # Multi-service deployment
│
📁 Configuration:
├── config/config.yaml # Main configuration
│
📁 Source Code:
├── src/
│ ├── models/ # Model architectures
│ ├── data/ # Data loading & preprocessing
│ ├── training/ # Training utilities
│ ├── quantization/ # PTQ & QAT
│ ├── signal_processing/ # FFT, wavelets, entropy
│ └── utils/ # Helper utilities
│
📁 Scripts:
├── scripts/
│ ├── generate_synthetic_data.py
│ └── calculate_threshold.py
│
📁 API:
└── api/
└── app.py # FastAPI server
- Customize Configuration: Edit
config/config.yamlfor your use case - Experiment Tracking: Enable MLflow or Weights & Biases in config
- Hyperparameter Tuning: Adjust model architecture, learning rate, etc.
- Edge Deployment: Deploy to Jetson Nano or Raspberry Pi
- Real Data: Replace synthetic data with real sensor data
- Production Monitoring: Set up Grafana dashboards for your metrics
- 📧 Email: mmmonani747@gmail.com
- 🐛 Issues: Create an issue on GitHub
- 📚 Documentation: See
/docsfolder for detailed guides - 💬 Discussions: Use GitHub Discussions for questions
| Platform | Model | Latency | Throughput |
|---|---|---|---|
| NVIDIA A4000 | INT8 TensorRT | ~0.5ms | 2000 samples/s |
| Jetson Nano | INT8 TensorRT | ~12ms | 83 samples/s |
| Raspberry Pi 4 | ONNX CPU | ~78ms | 13 samples/s |
| Intel i7 CPU | ONNX | ~15ms | 67 samples/s |
Happy Coding! 🚀
For detailed documentation, see README.md