3 files changed
+67
-21
No files matched your search
+5
-5
@@ -1,16 +1,16 @@
|
|||||||
num_of_gpus: -1
|
num_of_gpus: -1
|
||||||
|
|
||||||
hparams:
|
hparams:
|
||||||
max_epochs: 30
|
max_epochs: 20
|
||||||
batch_size: 64
|
batch_size: 64
|
||||||
lr: 0.001
|
lr: 0.001
|
||||||
accumulate_grad_batches: 1
|
accumulate_grad_batches: 1
|
||||||
gradient_clip_val: 0.5
|
gradient_clip_val: 0.5
|
||||||
lin1_size: 128
|
lin1_size: 256
|
||||||
lin2_size: 256
|
lin2_size: 256
|
||||||
lin3_size: 128
|
lin3_size: 128
|
||||||
output_size: 38
|
output_size: 10
|
||||||
weight_decay: 0.00001
|
weight_decay: 0.000001
|
||||||
split_ratio: 0.9
|
split_ratio: 0.9
|
||||||
|
|
||||||
resume:
|
resume:
|
||||||
@@ -39,6 +39,6 @@ callbacks:
|
|||||||
mode: "max"
|
mode: "max"
|
||||||
|
|
||||||
printing:
|
printing:
|
||||||
progress_bar_refresh_rate: 10
|
progress_bar_refresh_rate: 5
|
||||||
weights_summary: "top" # or "full"
|
weights_summary: "top" # or "full"
|
||||||
profiler: False
|
profiler: False
|
||||||
@@ -86,7 +86,7 @@ class MNISTDataModule(pl.LightningDataModule):
|
|||||||
return DataLoader(self.data_test, batch_size=self.batch_size)
|
return DataLoader(self.data_test, batch_size=self.batch_size)
|
||||||
|
|
||||||
|
|
||||||
class Cifar10DataModule(pl.LightningDataModule):
|
class CIFAR10DataModule(pl.LightningDataModule):
|
||||||
def __init__(self, data_dir="data/cifar10", batch_size=64, split_ratio=0.90):
|
def __init__(self, data_dir="data/cifar10", batch_size=64, split_ratio=0.90):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class SimpleLinearMNIST(nn.Module):
|
|||||||
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
|
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
|
||||||
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
|
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
|
||||||
self.layer_3 = nn.Linear(config["lin2_size"], config["lin3_size"])
|
self.layer_3 = nn.Linear(config["lin2_size"], config["lin3_size"])
|
||||||
self.layer_4 = nn.Linear(config["lin3_size"], 10)
|
self.layer_4 = nn.Linear(config["lin3_size"], config["output_size"])
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
batch_size, channels, width, height = x.size()
|
batch_size, channels, width, height = x.size()
|
||||||
@@ -42,20 +42,66 @@ class EfficientNetPretrained(nn.Module):
|
|||||||
# self.model = EfficientNet.from_pretrained('efficientnet-b7')
|
# self.model = EfficientNet.from_pretrained('efficientnet-b7')
|
||||||
|
|
||||||
for param in self.model.parameters():
|
for param in self.model.parameters():
|
||||||
param.requires_grad = False
|
param.requires_grad = True
|
||||||
|
|
||||||
self.model._fc = nn.Linear(self.model._fc.in_features, config["lin1_size"])
|
self.model._fc = nn.Sequential(
|
||||||
self.drop1 = nn.Dropout(p=0.25)
|
nn.Linear(self.model._fc.in_features, config["lin1_size"]),
|
||||||
self.lin_1 = nn.Linear(config["lin1_size"], config["lin2_size"])
|
nn.ReLU(),
|
||||||
self.drop2 = nn.Dropout(p=0.2)
|
nn.Dropout(p=0.25),
|
||||||
self.lin_2 = nn.Linear(config["lin2_size"], config["output_size"])
|
nn.Linear(config["lin1_size"], config["lin2_size"]),
|
||||||
|
nn.ReLU(),
|
||||||
|
nn.Dropout(p=0.2),
|
||||||
|
nn.Linear(config["lin2_size"], config["output_size"]),
|
||||||
|
nn.LogSoftmax(dim=1)
|
||||||
|
)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
x = self.model(x)
|
return self.model(x)
|
||||||
x = F.relu(x)
|
|
||||||
x = self.drop1(x)
|
|
||||||
x = self.lin_1(x)
|
class ResnetPretrained(nn.Module):
|
||||||
x = F.relu(x)
|
def __init__(self, config):
|
||||||
x = self.drop2(x)
|
super().__init__()
|
||||||
x = self.lin_2(x)
|
|
||||||
return torch.sigmoid(x)
|
self.model = models.resnet18(pretrained=True)
|
||||||
|
|
||||||
|
for param in self.model.parameters():
|
||||||
|
param.requires_grad = False
|
||||||
|
|
||||||
|
self.model.fc = nn.Sequential(
|
||||||
|
nn.Linear(self.model.fc.in_features, config["lin1_size"]),
|
||||||
|
nn.ReLU(),
|
||||||
|
nn.Dropout(p=0.15),
|
||||||
|
nn.Linear(config["lin1_size"], config["output_size"]),
|
||||||
|
nn.LogSoftmax(dim=1)
|
||||||
|
)
|
||||||
|
|
||||||
|
def forward(self, x):
|
||||||
|
return self.model(x)
|
||||||
|
|
||||||
|
|
||||||
|
# this model doesn't work yet, we wait for lightinng-bolts patch
|
||||||
|
# class ResnetPretrainedUnsupervised(nn.Module):
|
||||||
|
# """
|
||||||
|
# Trained without labels on Imagenet.
|
||||||
|
# Perhaps the features when trained without labels are much better for classification or other tasks.
|
||||||
|
# """
|
||||||
|
# def __init__(self, config):
|
||||||
|
# super().__init__()
|
||||||
|
#
|
||||||
|
# self.model = CPCV2(encoder='resnet18', pretrained='imagenet128').encoder
|
||||||
|
# # self.model = CPCV2(encoder='resnet18', pretrained='stl10').encoder
|
||||||
|
#
|
||||||
|
# for param in self.model.parameters():
|
||||||
|
# param.requires_grad = False
|
||||||
|
#
|
||||||
|
# self.model.fc = nn.Sequential(
|
||||||
|
# nn.Linear(self.model.fc.in_features, config["lin1_size"]),
|
||||||
|
# nn.ReLU(),
|
||||||
|
# nn.Dropout(p=0.15),
|
||||||
|
# nn.Linear(config["lin1_size"], config["output_size"]),
|
||||||
|
# nn.LogSoftmax()
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# def forward(self, x):
|
||||||
|
# return self.model(x)
|
||||||
Reference in new issue
Block a user