madhavkarthi commited on
Commit
fca8b64
·
verified ·
1 Parent(s): 50fb30c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +148 -0
README.md ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: mit
4
+ base_model: torchvision/resnet18
5
+ tags:
6
+ - image-classification
7
+ - scene-classification
8
+ - transfer-learning
9
+ - pytorch
10
+ - computer-vision
11
+ metrics:
12
+ - accuracy
13
+ model-index:
14
+ - name: scene-classifier-resnet18
15
+ results: []
16
+ ---
17
+
18
+ # Scene Classifier - ResNet18
19
+
20
+ This model is a fine-tuned version of ResNet-18 pretrained on ImageNet. It classifies images into 4 scene categories: cafe, gym, library, and outdoor.
21
+
22
+ ## Model description
23
+
24
+ This model uses a dataset of video frames extracted from recordings of different indoor and outdoor locations. The ResNet-18 architecture was chosen for its balance of accuracy and computational efficiency, using transfer learning from ImageNet pretrained weights. Only the final fully-connected layer was retrained for the 4-class classification task.
25
+
26
+ The model is part of a larger pipeline that generates contextual music based on scene classification combined with weather and temporal metadata.
27
+
28
+ ## Intended uses & limitations
29
+
30
+ **Intended use:**
31
+ - Scene classification for context-aware applications
32
+ - Image-to-music generation pipelines
33
+ - Indoor/outdoor scene detection
34
+ - Educational demonstrations of transfer learning
35
+
36
+ **Limitations:**
37
+ - Limited to 4 specific scene categories (cafe, gym, library, outdoor)
38
+ - Trained on relatively small dataset extracted from videos
39
+ - May not generalize well to significantly different scene compositions
40
+ - Performance may degrade on low-quality or heavily edited images
41
+ - Indoor scenes may be confused if they share similar visual features
42
+
43
+ ## Training and evaluation data
44
+
45
+ **Dataset:** Video frame extraction from 4 scene categories
46
+
47
+ - Classes: cafe, gym, library, outdoor
48
+ - Source: Personal video recordings of various locations
49
+ - Extraction: Sampled every 10th frame from videos
50
+ - Total frames: Approximately 2,400+ images
51
+ - Format: JPEG, 224x224 resolution after preprocessing
52
+
53
+ The dataset represents real-world indoor and outdoor environments with varying lighting conditions, angles, and compositions.
54
+
55
+ ## Training procedure
56
+
57
+ ### Data preprocessing
58
+
59
+ Images were preprocessed with resize to 224x224 and converted to tensors.
60
+
61
+ ### Model architecture
62
+
63
+ - Base model: ResNet-18 (ImageNet pretrained)
64
+ - Modified layer: Final fully-connected layer changed from 1000 classes to 4 classes
65
+ - Transfer learning: All layers except final FC layer retained pretrained weights
66
+
67
+ ### Training hyperparameters
68
+
69
+ The following hyperparameters were used during training:
70
+
71
+ - learning_rate: 1e-4
72
+ - train_batch_size: 32
73
+ - optimizer: Adam with default betas=(0.9, 0.999)
74
+ - loss_function: CrossEntropyLoss
75
+ - num_epochs: 3
76
+ - device: CUDA (GPU accelerated)
77
+
78
+ ### Training results
79
+
80
+ Training was conducted over 3 epochs with consistent loss reduction:
81
+
82
+ | Epoch | Training Loss | Status |
83
+ |:-----:|:-------------:|:------:|
84
+ | 1 | 0.4523 | ✓ |
85
+ | 2 | 0.2156 | ✓ |
86
+ | 3 | 0.1089 | ✓ |
87
+
88
+ Note: Formal validation metrics were not computed during training. Model was validated qualitatively on held-out images.
89
+
90
+ ## Usage
91
+
92
+ ### Loading the model
93
+
94
+ import torch
95
+ from torchvision import models, transforms
96
+ from PIL import Image
97
+
98
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
99
+ model = models.resnet18(weights=None)
100
+ model.fc = torch.nn.Linear(model.fc.in_features, 4)
101
+ model.load_state_dict(torch.load("pytorch_model.pth", map_location=device))
102
+ model = model.to(device)
103
+ model.eval()
104
+
105
+ transform = transforms.Compose([
106
+ transforms.Resize((224, 224)),
107
+ transforms.ToTensor(),
108
+ ])
109
+
110
+ class_labels = ["cafe", "gym", "library", "outdoor"]
111
+
112
+ ### Inference
113
+
114
+ image = Image.open("your_image.jpg")
115
+ if image.mode != 'RGB':
116
+ image = image.convert('RGB')
117
+
118
+ input_tensor = transform(image).unsqueeze(0).to(device)
119
+
120
+ with torch.no_grad():
121
+ outputs = model(input_tensor)
122
+ predicted_idx = outputs.argmax(dim=1).item()
123
+ predicted_class = class_labels[predicted_idx]
124
+ confidence = torch.softmax(outputs, dim=1)[0][predicted_idx].item()
125
+
126
+ print(f"Predicted: {predicted_class} (confidence: {confidence:.2%})")
127
+
128
+ ## Framework versions
129
+
130
+ - PyTorch: 2.0+
131
+ - Torchvision: 0.15+
132
+ - Python: 3.8+
133
+ - Pillow: 9.0+
134
+
135
+ ## Model Architecture Details
136
+
137
+ ResNet-18 Structure:
138
+ - Input: 3x224x224 RGB image
139
+ - Convolutional layers with residual connections
140
+ - Global average pooling
141
+ - Final FC layer: 512 to 4 classes
142
+ - Total parameters: approximately 11.7M (only approximately 2K trainable in final layer)
143
+
144
+ ## Additional Information
145
+
146
+ This model was developed as part of a course project (24-679) exploring multimodal AI systems.
147
+ It serves as the visual classification component in an image-to-music generation pipeline that combines scene recognition,
148
+ metadata extraction, weather context, and music synthesis.