File size: 3,570 Bytes
1745d01 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
---
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]
|