developerPushkal commited on
Commit
c4cdbf6
Β·
verified Β·
1 Parent(s): bd49b5b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +123 -0
README.md ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### **🌺 ResNet-50 Flowers Classification Model**
2
+
3
+ This repository hosts a fine-tuned **ResNet-50-based** model optimized for **flower classification** using the **Flowers-102 dataset**. The model classifies images into **102 different flower categories**.
4
+
5
+ ---
6
+
7
+ ## **πŸ“š Model Details**
8
+
9
+ - **Model Architecture**: ResNet-50
10
+ - **Task**: Multi-class Flower Classification
11
+ - **Dataset**: Flowers-102 ([Oxford Dataset](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/))
12
+ - **Framework**: PyTorch
13
+ - **Input Image Size**: 224x224
14
+ - **Number of Classes**: 102 (Different Flower Categories)
15
+ - **Quantization**: FP16 (for efficiency)
16
+
17
+ ---
18
+
19
+ ## **πŸš€ Usage**
20
+
21
+ ### **Installation**
22
+
23
+ ```bash
24
+ pip install torch torchvision pillow
25
+ ```
26
+
27
+ ### **Loading the Model**
28
+
29
+ ```python
30
+ import torch
31
+ import torchvision.models as models
32
+
33
+ # Step 1: Define the model architecture (Must match the trained model)
34
+ model = models.resnet50(pretrained=False)
35
+ model.fc = torch.nn.Linear(in_features=2048, out_features=102) # Ensure output matches 102 classes
36
+
37
+ # Step 2: Load the fine-tuned model weights
38
+ model_path = "/content/resnet50_flowers_model.pth" # Ensure the file is in the correct directory
39
+ model.load_state_dict(torch.load(model_path, map_location=torch.device("cpu")))
40
+
41
+ # Step 3: Set model to evaluation mode
42
+ model.eval()
43
+
44
+ print("βœ… Model loaded successfully and ready for inference!")
45
+ ```
46
+
47
+ ---
48
+
49
+ ### **πŸ“° Perform Flower Classification**
50
+
51
+ ```python
52
+ from PIL import Image
53
+ import torchvision.transforms as transforms
54
+
55
+ # Load the image
56
+ image_path = "/content/sample_flower.jpg" # Replace with your test image
57
+ image = Image.open(image_path).convert("RGB") # Ensure 3-channel format
58
+
59
+ # Define preprocessing (same as used during training)
60
+ transform = transforms.Compose([
61
+ transforms.Resize((224, 224)), # Resize to match model input
62
+ transforms.ToTensor(),
63
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
64
+ ])
65
+
66
+ # Apply transformations
67
+ image = transform(image).unsqueeze(0) # Add batch dimension
68
+
69
+ # Perform inference
70
+ with torch.no_grad():
71
+ output = model(image)
72
+
73
+ # Convert output to class prediction
74
+ predicted_class = torch.argmax(output, dim=1).item()
75
+
76
+ print(f"βœ… Predicted Flower Label: {predicted_class}")
77
+ ```
78
+
79
+ ---
80
+
81
+ ## **πŸ“Š Evaluation Results**
82
+
83
+ After fine-tuning, the model was evaluated on the **Flowers-102 Dataset**, achieving the following performance:
84
+
85
+ | **Metric** | **Score** |
86
+ |------------------|----------|
87
+ | **Accuracy** | 92.8% |
88
+ | **Precision** | 91.5% |
89
+ | **Recall** | 90.9% |
90
+ | **F1-Score** | 91.2% |
91
+ | **Inference Speed** | Fast (Optimized with FP16) |
92
+
93
+ ---
94
+
95
+ ## **πŸ› οΈ Fine-Tuning Details**
96
+
97
+ ### **Dataset**
98
+ The model was trained on the **Flowers-102 dataset**, which contains **8,189 flower images** classified into **102 categories**.
99
+
100
+ ### **Training Configuration**
101
+
102
+ - **Number of epochs**: 20
103
+ - **Batch size**: 16
104
+ - **Optimizer**: Adam
105
+ - **Learning rate**: 1e-4
106
+ - **Loss Function**: Cross-Entropy
107
+ - **Evaluation Strategy**: Validation at each epoch
108
+
109
+ ### **Quantization**
110
+ The model was quantized using **FP16 precision**, reducing latency and memory usage while maintaining high accuracy.
111
+
112
+ ---
113
+
114
+ ## **⚠️ Limitations**
115
+
116
+ - **Misclassification risk**: The model may incorrectly classify similar-looking flowers.
117
+ - **Dataset bias**: Performance may vary based on background, lighting, and image quality.
118
+ - **Generalization**: The model was trained on a specific dataset and may not generalize well to unseen flower species.
119
+
120
+ ---
121
+
122
+ βœ… **Use this fine-tuned ResNet-50 model for accurate and efficient flower classification!** πŸŒΊπŸš€
123
+