ayushsinha commited on
Commit
e8dd40e
ยท
verified ยท
1 Parent(s): c6b5d9d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +117 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### **๐Ÿฉบ ResNet-18 Cataract Detection System**
2
+
3
+ This repository hosts a quantized version of **ResNet-18-based** model optimized for **cataract detection** having two labels either normal or cataract. The model detects images into these 2 labels.
4
+
5
+ ---
6
+
7
+ ## **๐Ÿ“Œ Model Details**
8
+
9
+ - **Model Architecture**: ResNet-18
10
+ - **Task**: Cataract Detection System
11
+ - **Dataset**: Cataract Dataset ([Kaggle](https://www.kaggle.com/datasets/nandanp6/cataract-image-dataset))
12
+ - **Framework**: PyTorch
13
+ - **Input Image Size**: 224x224
14
+ - **Number of Classes**: 2
15
+ ---
16
+
17
+ ## **๐Ÿš€ Usage**
18
+
19
+ ### **Installation**
20
+
21
+ ```bash
22
+ pip install torch torchvision pillow
23
+ ```
24
+
25
+ ### **Loading the Model**
26
+
27
+ ```python
28
+ import torch
29
+ import torchvision.models as models
30
+ from huggingface_hub import hf_hub_download
31
+ import json
32
+ from PIL import Image
33
+ import torchvision.transforms as transforms
34
+
35
+ device = "cuda" if torch.cuda.is_available() else "cpu"
36
+
37
+ weights_path = hf_hub_download(repo_id="AventIQ-AI/resnet18-cataract-detection-system", filename="cataract_detection_resnet18_quantized.pth")
38
+ labels_path = hf_hub_download(repo_id="AventIQ-AI/resnet18-cataract-detection-system", filename="class_names.json")
39
+
40
+ with open(labels_path, "r") as f:
41
+ class_labels = json.load(f)
42
+
43
+ model = models.resnet18(pretrained=False)
44
+
45
+ num_classes = len(class_labels)
46
+ model.fc = torch.nn.Linear(in_features=512, out_features=num_classes)
47
+
48
+ model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))
49
+
50
+ model.eval()
51
+
52
+ print("Model loaded successfully!")
53
+ ```
54
+
55
+ ---
56
+
57
+ ### **๐Ÿ” Perform Classification**
58
+
59
+ ```python
60
+
61
+ transform = transforms.Compose([
62
+ transforms.Resize((224, 224)),
63
+ transforms.ToTensor(),
64
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
65
+ ])
66
+
67
+ def predict_image(image_path):
68
+ image = Image.open(image_path).convert("RGB")
69
+ image = transform(image).unsqueeze(0).to(device) # Add batch dimension
70
+
71
+ with torch.no_grad():
72
+ outputs = model(image)
73
+ _, predicted_class = torch.max(outputs, 1)
74
+
75
+ predicted_label = class_labels[predicted_class.item()]
76
+ print(f"Predicted Class: {predicted_label}")
77
+
78
+ # Example usage:
79
+ image_path = "your_image_path"
80
+ predict_image(image_path)
81
+ ```
82
+
83
+ ## **๐Ÿ“Š Evaluation Results**
84
+
85
+ After fine-tuning, the model was evaluated on the **Chest X-ray Pneumonia Dataset**, achieving the following performance:
86
+
87
+ | **Metric** | **Score** |
88
+ |------------------|----------|
89
+ | **Accuracy** | 97.52% |
90
+ | **Precision** | 98.31% |
91
+ | **Recall** | 96.67% |
92
+ | **F1-Score** | 97.48% |
93
+
94
+ ---
95
+
96
+ ## **๐Ÿ”ง Fine-Tuning Details**
97
+
98
+ ### **Dataset**
99
+ The model was trained on **Cataract Dataset** having two labels.
100
+
101
+ ### **Training Configuration**
102
+
103
+ - **Number of epochs**: 10
104
+ - **Batch size**: 32
105
+ - **Optimizer**: Adam
106
+ - **Learning rate**: 1e-4
107
+ - **Loss Function**: Cross-Entropy
108
+ - **Evaluation Strategy**: Validation at each epoch
109
+ ---
110
+
111
+ ## **โš ๏ธ Limitations**
112
+
113
+ - **Misclassification risk**: The model may produce **false positives or false negatives**. Always verify results with a radiologist.
114
+ - **Dataset bias**: Performance may be affected by **dataset distribution**. It may not generalize well to **different populations**.
115
+ - **Black-box nature**: Like all deep learning models, it does not explain why a prediction was made.
116
+
117
+ ---