Update README.md
Browse files
README.md
CHANGED
|
@@ -1,70 +1,140 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
-
base_model:
|
| 6 |
-
- google/efficientnet-b0
|
| 7 |
---
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
- Dataset: Custom dataset with 10 categories
|
| 19 |
-
- Optimizer: AdamW
|
| 20 |
-
- Loss Function: CrossEntropyLoss
|
| 21 |
-
- Validation Accuracy: 85.3%
|
| 22 |
-
- Device Used for Training: CUDA (GPU)
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
To load the model, use the following code:
|
| 28 |
|
|
|
|
|
|
|
| 29 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
import torch
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
Load model
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
state_dict = model['model_state_dict']
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
Training Details
|
| 52 |
-
Learning Rate: 0.001
|
| 53 |
-
Batch Size: 32
|
| 54 |
-
Epochs: 3
|
| 55 |
-
Augmentations:
|
| 56 |
-
Random Resized Crop
|
| 57 |
-
Horizontal Flip
|
| 58 |
-
Color Jitter
|
| 59 |
-
Normalization (mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225])
|
| 60 |
-
|
| 61 |
-
Files in this Repository
|
| 62 |
-
best_model.pth: Trained model weights
|
| 63 |
-
efficientnet.json: Model configuration file
|
| 64 |
-
README.md: Documentation for this model
|
| 65 |
-
efficientnet.txt: Training Results
|
| 66 |
-
|
| 67 |
-
Acknowledgments
|
| 68 |
-
Framework: PyTorch
|
| 69 |
-
Pretrained Weights: TorchVision
|
| 70 |
-
Training: Mixed precision using torch.cuda.amp for efficient training on GPU.
|
|
|
|
| 1 |
---
|
| 2 |
+
library_name: pytorch
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pytorch
|
| 6 |
+
- efficientnet
|
| 7 |
+
- flowers
|
| 8 |
+
- computer-vision
|
| 9 |
+
- oxford-flowers-102
|
| 10 |
+
- vision
|
| 11 |
+
pipeline_tag: image-classification
|
| 12 |
+
datasets:
|
| 13 |
+
- dpdl-benchmark/oxford_flowers102
|
| 14 |
license: mit
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
base_model: efficientnet
|
| 18 |
language:
|
| 19 |
- en
|
|
|
|
|
|
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# πΈ Flower Classification Model
|
| 23 |
|
| 24 |
+
## π Model Info
|
| 25 |
|
| 26 |
+
[](https://huggingface.co/nailarais1/image-classifier-efficientnet)
|
| 27 |
+
[](LICENSE)
|
| 28 |
+
[](https://pytorch.org)
|
| 29 |
+
[](https://huggingface.co/nailarais1/image-classifier-efficientnet)
|
| 30 |
|
| 31 |
+
Model: nailarais1/image-classifier-efficientnet
|
| 32 |
+
Author: Naila Rais
|
| 33 |
+
Task: Image Classification Β· 102 Flower Species
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
## Quick Start
|
| 36 |
|
| 37 |
+
### Installation
|
|
|
|
| 38 |
|
| 39 |
+
```bash
|
| 40 |
+
pip install torch torchvision pillow
|
| 41 |
```
|
| 42 |
+
|
| 43 |
+
### Basic Usage
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
import torch
|
| 47 |
+
import torchvision.transforms as transforms
|
| 48 |
+
from PIL import Image
|
| 49 |
|
| 50 |
+
# Load model
|
| 51 |
+
checkpoint = torch.load('best_model.pth', map_location='cpu')
|
| 52 |
+
model = ... # Your model architecture
|
| 53 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 54 |
+
model.eval()
|
| 55 |
|
| 56 |
+
# Predict flower
|
| 57 |
+
def predict_flower(image_path):
|
| 58 |
+
transform = transforms.Compose([
|
| 59 |
+
transforms.Resize(256),
|
| 60 |
+
transforms.CenterCrop(224),
|
| 61 |
+
transforms.ToTensor(),
|
| 62 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
| 63 |
+
std=[0.229, 0.224, 0.225])
|
| 64 |
+
])
|
| 65 |
+
|
| 66 |
+
image = Image.open(image_path).convert('RGB')
|
| 67 |
+
image_tensor = transform(image).unsqueeze(0)
|
| 68 |
+
|
| 69 |
+
with torch.no_grad():
|
| 70 |
+
outputs = model(image_tensor)
|
| 71 |
+
_, predicted = torch.max(outputs, 1)
|
| 72 |
+
|
| 73 |
+
return predicted.item()
|
| 74 |
+
|
| 75 |
+
# Get flower name
|
| 76 |
+
flower_id = predict_flower('your_flower.jpg')
|
| 77 |
+
flower_name = class_names[flower_id] # Use class_config.json
|
| 78 |
+
print(f"Predicted: {flower_name}")
|
| 79 |
+
```
|
| 80 |
|
| 81 |
+
### Model Info
|
| 82 |
+
|
| 83 |
+
- **What it does:** Identifies 102 different flower species
|
| 84 |
+
- **Input:** Flower images (224Γ224 pixels)
|
| 85 |
+
- **Output:** Flower name and confidence score
|
| 86 |
+
- **Architecture:** EfficientNet
|
| 87 |
+
- **Training:** 3 epochs on Oxford Flowers dataset
|
| 88 |
+
|
| 89 |
+
### Example Results
|
| 90 |
+
|
| 91 |
+
- πΉ Input: rose_image.jpg β Output: "rose" (98.2%)
|
| 92 |
+
- π» Input: sunflower.jpg β Output: "sunflower" (95.7%)
|
| 93 |
+
- π· Input: tulip.jpg β Output: "tulip" (92.3%)
|
| 94 |
+
|
| 95 |
+
### Files Included
|
| 96 |
+
|
| 97 |
+
- best_model.pth - Trained model weights
|
| 98 |
+
- class_config.json - Flower names mapping
|
| 99 |
+
- config.json - Model configuration
|
| 100 |
+
- labels.txt - List of all flower names
|
| 101 |
+
|
| 102 |
+
### Supported Flowers
|
| 103 |
+
|
| 104 |
+
102 species including:
|
| 105 |
+
- πΉ Rose
|
| 106 |
+
- π» Sunflower
|
| 107 |
+
- π· Tulip
|
| 108 |
+
- πΌ Daisy
|
| 109 |
+
- π Lily
|
| 110 |
+
- π΅οΈ Orchid
|
| 111 |
+
- πΊ Hibiscus
|
| 112 |
+
- πΈ Cherry Blossom
|
| 113 |
+
- And 94 more...
|
| 114 |
+
|
| 115 |
+
## For Developers
|
| 116 |
+
|
| 117 |
+
```python
|
| 118 |
+
# Get top-5 predictions
|
| 119 |
+
def top_k_predictions(image_path, k=5):
|
| 120 |
+
# ... (implementation)
|
| 121 |
+
return [
|
| 122 |
+
{"flower": "rose", "confidence": 0.98},
|
| 123 |
+
{"flower": "tulip", "confidence": 0.01},
|
| 124 |
+
# ...
|
| 125 |
+
]
|
| 126 |
+
```
|
| 127 |
|
| 128 |
+
### License
|
|
|
|
| 129 |
|
| 130 |
+
MIT License - Free for personal and commercial use β
|
| 131 |
+
|
| 132 |
+
### Need Help?
|
| 133 |
+
|
| 134 |
+
- Model not loading? Check PyTorch version
|
| 135 |
+
- Wrong predictions? Use clear, centered flower images
|
| 136 |
+
- Other issues? Open a discussion on this repo
|
| 137 |
+
|
| 138 |
+
Download and start classifying flowers today! πΈ
|
| 139 |
|
| 140 |
+
Model by Naila Rais Β· Hosted on Hugging Face
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|