|
--- |
|
license: mit |
|
language: |
|
- en |
|
metrics: |
|
- accuracy |
|
pipeline_tag: image-classification |
|
tags: |
|
- code |
|
library_name: transformers |
|
--- |
|
|
|
|
|
# ResNet Cat-Dog Classifier |
|
|
|
This repository contains a ResNet-based convolutional neural network trained to classify images as either cats or dogs. The model achieves an accuracy of 90.27% on a test dataset and is fine-tuned using transfer learning on the ImageNet dataset. It uses PyTorch for training and inference. |
|
|
|
## Model Details |
|
|
|
### Architecture: |
|
- Backbone: ResNet-18 |
|
- Input Size: 128x128 RGB images |
|
- Output: Binary classification (Cat or Dog) |
|
|
|
### Training Details: |
|
- Dataset: Kaggle Cats and Dogs dataset |
|
- Loss Function: Cross-entropy loss |
|
- Optimizer: Adam optimizer |
|
- Learning Rate: 0.001 |
|
- Epochs: 15 |
|
- Batch Size: 32 |
|
|
|
### Performance: |
|
- Accuracy: 90.27% on test images |
|
- Training Time: Approximately 1 hour on NVIDIA GTX 1080 Ti |
|
|
|
## Usage |
|
|
|
### Installation: |
|
- Dependencies: PyTorch, TorchVision, matplotlib |
|
|
|
### Inference: |
|
```python |
|
import torch |
|
from torchvision import transforms |
|
from PIL import Image |
|
|
|
# Load the model |
|
model = torch.hub.load('your-username/your-repository', 'resnet_cat_dog_classifier') |
|
|
|
# Define the transformation |
|
transform = transforms.Compose([ |
|
transforms.Resize((128, 128)), |
|
transforms.ToTensor(), |
|
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), |
|
]) |
|
|
|
# Load an image |
|
image_path = 'path/to/your/image.jpg' |
|
image = Image.open(image_path) |
|
image = transform(image) |
|
image = image.unsqueeze(0) # Add batch dimension |
|
|
|
# Make a prediction |
|
model.eval() |
|
with torch.no_grad(): |
|
outputs = model(image) |
|
temp, predicted = torch.max(outputs, 1) |
|
|
|
# Output the prediction |
|
print(f'The predicted class for the image is: {"Cat" if predicted.item() == 0 else "Dog"}') |
|
|