Anna Rachkova commited on
Commit
1ea541c
·
2 Parent(s): e6d94e8 89f7e00

Merge branch 'models' into develop

Browse files

Feat: Integrate improved BetterCNN architecture and ClearML training logic.
Fixes: Resolved conflicts in run_training.py related to model initialization.

.gitignore CHANGED
@@ -1,10 +1,8 @@
1
- <<<<<<< HEAD
2
  .vscode/
3
  .venv/
4
  .vscode/
5
  .models/
6
  __pycache__/
7
- =======
8
 
9
  # Python environment
10
  venv/
@@ -18,4 +16,4 @@ __pycache__/
18
 
19
  # Generated files from data_preparation.py
20
  class_distribution.png
21
- >>>>>>> 04cb88662062ef6b880c627546d067fa0cedfa8b
 
 
1
  .vscode/
2
  .venv/
3
  .vscode/
4
  .models/
5
  __pycache__/
 
6
 
7
  # Python environment
8
  venv/
 
16
 
17
  # Generated files from data_preparation.py
18
  class_distribution.png
19
+
best_model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23a4c08eaad4b40290eca84e6a8fa3e1d69bdf4312d5db6db5de96d1d8753024
3
+ size 130261986
models/modelTwo.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
+
5
+ class BetterCNN(nn.Module):
6
+ def __init__(self, noOfClasses=39):
7
+ super(BetterCNN, self).__init__()
8
+
9
+ # 32 Channels
10
+ # We use padding=1 to keep spatial size same before pooling
11
+ self.conv1 = nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1)
12
+ self.bn1 = nn.BatchNorm2d(32)
13
+
14
+ # 64 Channels
15
+ self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
16
+ self.bn2 = nn.BatchNorm2d(64)
17
+
18
+ # 128 Channels
19
+ self.conv3 = nn.Conv2d(64, 128, kernel_size=3, padding=1)
20
+ self.bn3 = nn.BatchNorm2d(128)
21
+
22
+ # 256 Channels
23
+ self.conv4 = nn.Conv2d(128, 256, kernel_size=3, padding=1)
24
+ self.bn4 = nn.BatchNorm2d(256)
25
+
26
+ # Pooling layer
27
+ self.pool = nn.MaxPool2d(2, 2)
28
+
29
+ # Adaptive Pooling
30
+ self.adaptive_pool = nn.AdaptiveAvgPool2d((4, 4))
31
+
32
+ # Classification Head
33
+ self.fc1 = nn.Linear(256 * 4 * 4, 1024)
34
+ self.dropout = nn.Dropout(0.5) # Dropout after Linear layer
35
+
36
+ self.fc2 = nn.Linear(1024, 512)
37
+ self.fc3 = nn.Linear(512, noOfClasses)
38
+
39
+ def forward(self, x):
40
+ # Block 1
41
+ x = self.conv1(x)
42
+ x = self.bn1(x) # BatchNorm
43
+ x = F.relu(x)
44
+ x = self.pool(x)
45
+
46
+ # Block 2
47
+ x = self.pool(F.relu(self.bn2(self.conv2(x))))
48
+
49
+ # Block 3
50
+ x = self.pool(F.relu(self.bn3(self.conv3(x))))
51
+
52
+ # Block 4
53
+ x = self.pool(F.relu(self.bn4(self.conv4(x))))
54
+
55
+ # Adapt & Flatten
56
+ x = self.adaptive_pool(x)
57
+ x = torch.flatten(x, 1) # Flattens to (Batch, 4096)
58
+
59
+ # Dense Layers
60
+ x = F.relu(self.fc1(x))
61
+ x = self.dropout(x) # Regularization
62
+ x = F.relu(self.fc2(x))
63
+ x = self.fc3(x) # No activation needed here (handled by CrossEntropyLoss)
64
+
65
+ return x
subset_indices.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:972615a5b506b5ee2490f61866c26a4a2f9e2498c0baedb195a2a0d10a62e76f
3
+ size 111016
trainingModel/run_training.py CHANGED
@@ -3,7 +3,7 @@ from clearml import Task
3
  from dataPrep.helpers.clearml_data import extract_latest_data_task
4
 
5
  import torch
6
- from models.modelOne import modelOne
7
  from trainingModel.helpers.Training import train_model
8
 
9
 
@@ -37,7 +37,7 @@ training_task.connect(training_config)
37
 
38
 
39
  # -------- Build the ML model --------
40
- model = modelOne(noOfClasses=training_config["num_classes"])
41
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
42
  model.to(device)
43
 
 
3
  from dataPrep.helpers.clearml_data import extract_latest_data_task
4
 
5
  import torch
6
+ from models.modelTwo import BetterCNN
7
  from trainingModel.helpers.Training import train_model
8
 
9
 
 
37
 
38
 
39
  # -------- Build the ML model --------
40
+ model = BetterCNN(noOfClasses=training_config["num_classes"])
41
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
42
  model.to(device)
43