Spaces:
Runtime error
Runtime error
update lightning_model
Browse files- lightningmodel.py +9 -7
lightningmodel.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import math
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
|
|
5 |
import torch
|
6 |
import torch.nn as nn
|
7 |
import torch.nn.functional as F
|
@@ -24,6 +25,7 @@ from PIL import Image
|
|
24 |
from pytorch_grad_cam import GradCAM
|
25 |
from pytorch_grad_cam.utils.image import show_cam_on_image
|
26 |
|
|
|
27 |
seed_everything(7)
|
28 |
|
29 |
|
@@ -109,9 +111,9 @@ class Net_S13(nn.Module):
|
|
109 |
O = 10
|
110 |
self.lastLayer = nn.Linear(I, O)
|
111 |
|
112 |
-
self.aGAP = nn.AdaptiveAvgPool2d((1, 1))
|
113 |
-
self.flat = nn.Flatten(1, -1)
|
114 |
-
self.gap = nn.AvgPool2d(avg)
|
115 |
self.drop = nn.Dropout(drop)
|
116 |
|
117 |
# convolution Block
|
@@ -186,11 +188,10 @@ class Net_S13(nn.Module):
|
|
186 |
self.printf(4.0, x, "pool input")
|
187 |
x = self.pool(x)
|
188 |
self.printf(4.1, x, "pool output")
|
189 |
-
self.printEmpty()
|
190 |
-
|
191 |
-
# x = x.view(-1, 10)
|
192 |
-
self.printf(4.2, x, "For showing before last layer")
|
193 |
x = x.view(x.size(0), -1)
|
|
|
|
|
|
|
194 |
self.printf(5.0, x, "last layer input") #512, 1, 1
|
195 |
x = self.lastLayer(x)
|
196 |
# x = self.gap(x)
|
@@ -242,6 +243,7 @@ class LitResnet(LightningModule):
|
|
242 |
self.evaluate(batch, "test")
|
243 |
|
244 |
def configure_optimizers(self):
|
|
|
245 |
optimizer = torch.optim.SGD(
|
246 |
self.parameters(),
|
247 |
lr=self.hparams.lr,
|
|
|
2 |
import math
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
+
import seaborn as sn
|
6 |
import torch
|
7 |
import torch.nn as nn
|
8 |
import torch.nn.functional as F
|
|
|
25 |
from pytorch_grad_cam import GradCAM
|
26 |
from pytorch_grad_cam.utils.image import show_cam_on_image
|
27 |
|
28 |
+
|
29 |
seed_everything(7)
|
30 |
|
31 |
|
|
|
111 |
O = 10
|
112 |
self.lastLayer = nn.Linear(I, O)
|
113 |
|
114 |
+
# self.aGAP = nn.AdaptiveAvgPool2d((1, 1))
|
115 |
+
# self.flat = nn.Flatten(1, -1)
|
116 |
+
# self.gap = nn.AvgPool2d(avg)
|
117 |
self.drop = nn.Dropout(drop)
|
118 |
|
119 |
# convolution Block
|
|
|
188 |
self.printf(4.0, x, "pool input")
|
189 |
x = self.pool(x)
|
190 |
self.printf(4.1, x, "pool output")
|
|
|
|
|
|
|
|
|
191 |
x = x.view(x.size(0), -1)
|
192 |
+
self.printf(4.2, x, "after view")
|
193 |
+
self.printEmpty()
|
194 |
+
|
195 |
self.printf(5.0, x, "last layer input") #512, 1, 1
|
196 |
x = self.lastLayer(x)
|
197 |
# x = self.gap(x)
|
|
|
243 |
self.evaluate(batch, "test")
|
244 |
|
245 |
def configure_optimizers(self):
|
246 |
+
BATCH_SIZE = 256 if torch.cuda.is_available() else 64
|
247 |
optimizer = torch.optim.SGD(
|
248 |
self.parameters(),
|
249 |
lr=self.hparams.lr,
|