|
--- |
|
library_name: pytorch |
|
tags: |
|
- anomaly-detection |
|
- autoencoder |
|
- plant-detection |
|
- computer-vision |
|
- pytorch-lightning |
|
datasets: |
|
- custom-plant-dataset |
|
metrics: |
|
- reconstruction-error |
|
- threshold-based-classification |
|
pipeline_tag: image-classification |
|
--- |
|
|
|
# plant-detector |
|
|
|
## Model Description |
|
|
|
Convolutional Autoencoder for plant anomaly detection |
|
|
|
This is a Convolutional Autoencoder (CAE) trained for plant anomaly detection. The model learns to reconstruct plant images and detects anomalies based on reconstruction error. |
|
|
|
## Model Details |
|
|
|
- **Model Type**: Convolutional Autoencoder |
|
- **Framework**: PyTorch Lightning |
|
- **Task**: Anomaly Detection / Plant Classification |
|
- **Input**: RGB images (224x224) |
|
- **Output**: Reconstruction + anomaly score |
|
|
|
## Training Details |
|
|
|
- **Architecture**: Encoder-Decoder with skip connections |
|
- **Loss Function**: Mean Squared Error (MSE) |
|
- **Optimizer**: AdamW |
|
- **Learning Rate**: 0.0001 |
|
- **Batch Size**: 32 |
|
- **Epochs**: N/A |
|
- **Dataset Size**: N/A images |
|
|
|
## Performance Metrics |
|
|
|
- **Validation Loss**: N/A |
|
- **Threshold**: 0.5687 |
|
- **Mean Reconstruction Error**: N/A |
|
- **Std Reconstruction Error**: N/A |
|
- **Anomaly Rate**: N/A |
|
|
|
## Normalization Statistics |
|
|
|
The model expects input images to be normalized with: |
|
- **Mean**: [0.4682, 0.4865, 0.3050] |
|
- **Std**: [0.2064, 0.1995, 0.1961] |
|
|
|
## Usage |
|
|
|
### PyTorch Lightning Checkpoint |
|
|
|
```python |
|
from annomallyDet.models.lit_models.lit_cae import LitCAE |
|
|
|
# Load the model |
|
model = LitCAE.load_from_checkpoint("plant_anomaly_detector.ckpt") |
|
model.eval() |
|
|
|
# Make prediction |
|
reconstruction_error = model.get_reconstruction_error(input_tensor) |
|
is_anomaly = reconstruction_error > 0.5687 |
|
``` |
|
|
|
### Mobile Deployment (TorchScript Lite) |
|
|
|
```python |
|
import torch |
|
|
|
# Load mobile model |
|
model = torch.jit.load("plant_anomaly_detector.ptl") |
|
reconstruction = model(input_tensor) |
|
|
|
# Calculate reconstruction error |
|
error = torch.mean((input_tensor - reconstruction) ** 2) |
|
is_anomaly = error > 0.5687 |
|
``` |
|
|
|
### Flutter Integration |
|
|
|
See the included `flutter_integration_example.dart` for complete Flutter app integration using `flutter_pytorch_lite`. |
|
|
|
## Files Included |
|
|
|
- `plant_anomaly_detector.ckpt`: PyTorch Lightning checkpoint |
|
- `plant_anomaly_detector.ptl`: TorchScript Lite model for mobile deployment |
|
- `config.json`: Model configuration and metadata |
|
- `flutter_integration_example.dart`: Flutter integration example |
|
- `normalization_stats.json`: Dataset normalization statistics |
|
|
|
## Model Architecture |
|
|
|
``` |
|
Input (3, 224, 224) |
|
β |
|
Encoder: Conv2d β BatchNorm β LeakyReLU β Dropout |
|
[32, 64, 128, 256] channels |
|
β |
|
Latent Space (128 dimensions) |
|
β |
|
Decoder: ConvTranspose2d β BatchNorm β LeakyReLU β Dropout |
|
[256, 128, 64, 32] channels |
|
β |
|
Output (3, 224, 224) |
|
``` |
|
|
|
## Anomaly Detection Logic |
|
|
|
1. **Training**: Model learns to reconstruct normal plant images |
|
2. **Inference**: Calculate reconstruction error (MSE) |
|
3. **Decision**: If error > threshold β Anomaly (not a plant) |
|
4. **Confidence**: Distance from threshold indicates confidence |
|
|
|
## Limitations |
|
|
|
- Trained specifically on plant images |
|
- Performance depends on similarity to training data |
|
- May struggle with novel plant species not in training set |
|
- Threshold may need adjustment for different use cases |
|
|
|
## Citation |
|
|
|
```bibtex |
|
@misc{plant_anomaly_detector, |
|
title={Plant Anomaly Detection using Convolutional Autoencoder}, |
|
author={Your Name}, |
|
year={2024}, |
|
howpublished={\url{https://huggingface.co/YOUR_USERNAME/plant-detector}}, |
|
} |
|
``` |
|
|
|
## License |
|
|
|
[Specify your license here] |
|
|