Update README.md
Browse filesAdded model card .
README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
datasets:
|
| 4 |
+
- alkzar90/NIH-Chest-X-ray-dataset
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
metrics:
|
| 8 |
+
- roc_auc
|
| 9 |
+
base_model:
|
| 10 |
+
- galactixx/Torchvision-DenseNet121-a639ec97
|
| 11 |
+
pipeline_tag: image-classification
|
| 12 |
+
tags:
|
| 13 |
+
- Ai
|
| 14 |
+
- fine-tuned
|
| 15 |
+
- image-classification
|
| 16 |
---
|
| 17 |
+
# DenseNet121 Image Classifier
|
| 18 |
+
|
| 19 |
+
This model is a custom image classifier built with **PyTorch**, leveraging a pretrained **DenseNet121** backbone. The model extracts rich visual features from the pretrained weights and uses a custom classification head to predict the target categories.
|
| 20 |
+
|
| 21 |
+
## Model Details
|
| 22 |
+
|
| 23 |
+
- **Developed by:** [Aditya chaubey]
|
| 24 |
+
- **Model type:** Image Classification (Convolutional Neural Network)
|
| 25 |
+
- **Architecture:** DenseNet121 (Dense Convolutional Network)
|
| 26 |
+
- **Library:** PyTorch
|
| 27 |
+
- **License:** Mit
|
| 28 |
+
- **Pretrained Backbone:** torchvision.models.densenet121
|
| 29 |
+
|
| 30 |
+
## Intended Uses & Limitations
|
| 31 |
+
|
| 32 |
+
### Intended Uses
|
| 33 |
+
- Automated classification of images into [14] categories.
|
| 34 |
+
- Fine-tuning or feature extraction for related computer vision tasks.
|
| 35 |
+
|
| 36 |
+
### Limitations & Bias
|
| 37 |
+
- **Image Resolution:** The backbone expects standard image sizes (typically 322x322 pixels). Performance may degrade on highly distorted or low-resolution images.
|
| 38 |
+
- **Domain Bias:** The model inherits the features learned from ImageNet. It may perform poorly on highly niche domains (e.g., specific medical imaging or satellite data) unless heavily fine-tuned on target data.
|
| 39 |
+
|
| 40 |
+
## How to Get Started with the Model
|
| 41 |
+
|
| 42 |
+
You can load and run inference with this model directly using standard PyTorch tools.
|
| 43 |
+
|
| 44 |
+
First, ensure you have the `huggingface_hub`, `torch`, and `torchvision` libraries installed:
|
| 45 |
+
```bash
|
| 46 |
+
pip install torch torchvision huggingface_hub pillow
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
Use the snippet below to download the model weights and run a prediction:
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
import torch
|
| 53 |
+
import torchvision.models as models
|
| 54 |
+
import torchvision.transforms as transforms
|
| 55 |
+
from PIL import Image
|
| 56 |
+
from huggingface_hub import hf_hub_download
|
| 57 |
+
|
| 58 |
+
# 1. Recreate the model architecture
|
| 59 |
+
model = models.densenet121(weights=None) # Initialize architecture
|
| 60 |
+
|
| 61 |
+
# Replace the final classifier head to match your custom number of classes
|
| 62 |
+
# Example: num_classes = 10 (Change this to your actual number of classes)
|
| 63 |
+
num_classes = 10
|
| 64 |
+
model.classifier = torch.nn.Linear(model.classifier.in_features, num_classes)
|
| 65 |
+
|
| 66 |
+
# 2. Download and load the weights from Hugging Face Hub
|
| 67 |
+
# Replace 'your-username/your-model-name' with your repository ID
|
| 68 |
+
checkpoint_path = hf_hub_download(repo_id="adityachaubey/ChestNet", filename="model.pt")
|
| 69 |
+
model.load_state_dict(torch.load(checkpoint_path, map_location=torch.device('cpu')))
|
| 70 |
+
model.eval()
|
| 71 |
+
|
| 72 |
+
# 3. Prepare the input image
|
| 73 |
+
transform = transforms.Compose([
|
| 74 |
+
transforms.Resize(256),
|
| 75 |
+
transforms.CenterCrop(224),
|
| 76 |
+
transforms.ToTensor(),
|
| 77 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 78 |
+
])
|
| 79 |
+
|
| 80 |
+
image = Image.open("path_to_your_image.jpg").convert("RGB")
|
| 81 |
+
input_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
| 82 |
+
|
| 83 |
+
# 4. Run inference
|
| 84 |
+
with torch.no_grad():
|
| 85 |
+
outputs = model(input_tensor)
|
| 86 |
+
probabilities = torch.nn.functional.softmax(outputs[0], dim=0)
|
| 87 |
+
predicted_class = torch.argmax(probabilities).item()
|
| 88 |
+
|
| 89 |
+
print(f"Predicted Class Index: {predicted_class}")
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## Training Details
|
| 93 |
+
|
| 94 |
+
### Training Data
|
| 95 |
+
The model was fine-tuned on the [NIH-Chest-X-ray-dataste] dataset, which contains [112,120] images across [14] classes.
|
| 96 |
+
|
| 97 |
+
### Data Preprocessing
|
| 98 |
+
Images were resized, cropped to 224x224, and normalized using standard ImageNet mean and standard deviation values:
|
| 99 |
+
- **Mean:** `[0.485, 0.456, 0.406]`
|
| 100 |
+
- **Std:** `[0.229, 0.224, 0.225]`
|
| 101 |
+
|
| 102 |
+
### Training Hyperparameters
|
| 103 |
+
- **Optimizer:** [Adam]
|
| 104 |
+
- **Learning Rate:** [1e-5]
|
| 105 |
+
- **Batch Size:** [e.g., 32]
|
| 106 |
+
- **Epochs:** [10]
|
| 107 |
+
|
| 108 |
+
## Evaluation Results
|
| 109 |
+
|
| 110 |
+
The model achieved the following performance metrics on the validation/test set:
|
| 111 |
+
- **Accuracy:** [83%]
|
| 112 |
+
- **Loss:** [Insert validation loss]
|