DenseNet121 Image Classifier

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.

Model Details

  • Developed by: [Aditya chaubey]
  • Model type: Image Classification (Convolutional Neural Network)
  • Architecture: DenseNet121 (Dense Convolutional Network)
  • Library: PyTorch
  • License: Mit
  • Pretrained Backbone: torchvision.models.densenet121

Intended Uses & Limitations

Intended Uses

  • Automated classification of images into [14] categories.
  • Fine-tuning or feature extraction for related computer vision tasks.

Limitations & Bias

  • Image Resolution: The backbone expects standard image sizes (typically 322x322 pixels). Performance may degrade on highly distorted or low-resolution images.
  • 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.

How to Get Started with the Model

You can load and run inference with this model directly using standard PyTorch tools.

First, ensure you have the huggingface_hub, torch, and torchvision libraries installed:

pip install torch torchvision huggingface_hub pillow

Use the snippet below to download the model weights and run a prediction:

import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
from huggingface_hub import hf_hub_download

# 1. Recreate the model architecture
model = models.densenet121(weights=None)  # Initialize architecture

# Replace the final classifier head to match your custom number of classes
# Example: num_classes = 10 (Change this to your actual number of classes)
num_classes = 10 
model.classifier = torch.nn.Linear(model.classifier.in_features, num_classes)

# 2. Download and load the weights from Hugging Face Hub
# Replace 'your-username/your-model-name' with your repository ID
checkpoint_path = hf_hub_download(repo_id="adityachaubey/ChestNet", filename="model.pt")
model.load_state_dict(torch.load(checkpoint_path, map_location=torch.device('cpu')))
model.eval()

# 3. Prepare the input image
transform = transforms.Compose([
    transforms.Resize(256),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

image = Image.open("path_to_your_image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)  # Add batch dimension

# 4. Run inference
with torch.no_grad():
    outputs = model(input_tensor)
    probabilities = torch.nn.functional.softmax(outputs[0], dim=0)
    predicted_class = torch.argmax(probabilities).item()

print(f"Predicted Class Index: {predicted_class}")

Training Details

Training Data

The model was fine-tuned on the [NIH-Chest-X-ray-dataste] dataset, which contains [112,120] images across [14] classes.

Data Preprocessing

Images were resized, cropped to 224x224, and normalized using standard ImageNet mean and standard deviation values:

  • Mean: [0.485, 0.456, 0.406]
  • Std: [0.229, 0.224, 0.225]

Training Hyperparameters

  • Optimizer: [Adam]
  • Learning Rate: [1e-5]
  • Batch Size: [e.g., 32]
  • Epochs: [10]

Evaluation Results

The model achieved the following performance metrics on the validation/test set:

  • Accuracy: [83%]
  • Loss: [Insert validation loss]
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for adityachaubey/ChestNet

Finetuned
(1)
this model

Dataset used to train adityachaubey/ChestNet