This project uses a pre-trained Vision Transformer (ViT) model (google/vit-base-patch16-224) to classify images from the Describable Texture Dataset (DTD) into 47 texture categories.
The model achieves high accuracy through transfer learning and data augmentation techniques.
Name: Describable Texture Dataset (DTD)
Classes: 47 texture categories (e.g., banded, blotchy, bubbly, etc.)
Structure:
dtd/
└── images/
├── banded/
├── blotchy/
├── bubbly/
└── ...
Setup:
- Download and extract the dataset from the official source.
- Place it in your Google Drive:
/content/drive/MyDrive/dtd/images
This code is designed to run on Google Colab with GPU enabled.
Required Libraries:
pip install torch torchvision transformers tqdm- Base Model: ViT Base (Patch16-224)
- Modification: Final classification head modified for 47 classes instead of 1000.
- Pretrained: Yes, on ImageNet, then fine-tuned on DTD.
Training:
RandomResizedCropRandomHorizontalFlipColorJitterRandomRotationNormalize(using ViT's mean/std)
Validation & Testing:
Resize→CenterCrop→Normalize
- Train: 70%
- Validation: 15%
- Test: 15%
| Metric | Value |
|---|---|
| Best Validation Acc | 78.25% |
| Total Classes | 47 |
def evaluate(model, loader):
# Evaluation logic
...# Save
torch.save(model.state_dict(), "vit_texture_model.pth")
# Load
model.load_state_dict(torch.load("vit_texture_model.pth"))