-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpl_model_selfsupervised.py
49 lines (35 loc) · 1.61 KB
/
pl_model_selfsupervised.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import torch
import torch.nn as nn
import torch.nn.functional as F
from models.vit_model import VisionTransformerModule
from models.convnext_model import ConvNext
from models.mlpmixer_model import MLPMixerModule
from models.swin_transformer_model import SwinTransformerModule
from models.densenet_model import DenseNetModule
from utils import return_optimizer, return_lr_scheduler
import pytorch_lightning as pl
class SSLBaseModule(pl.LightningModule):
def __init__(self, args):
super().__init__()
self.args = args
if args.model_name == 'vit_30_16':
self.model = VisionTransformerModule(model_name=args.model_name, is_ssl=True, **self.args.model)
elif args.model_name == 'convnext_extra':
self.model = ConvNext(model_name=args.model_name, is_ssl=True, **self.args.model)
elif args.model_name == 'mlp':
self.model = MLPMixerModule(args=args, model_name=args.model_name, is_ssl=True, **self.args.model)
elif args.model_name in ['densenet201', 'densenet_extra']:
self.model = DenseNetModule(model_name=args.model_name, is_ssl=True, **self.args.model)
elif args.model_name in ['swin_t', 'swin_s', 'swin_b', 'swin_extra']:
self.model = SwinTransformerModule(model_name=args.model_name, is_ssl=True, **self.args.model)
else:
self.model = None
assert self.model is not None
def forward(self, x):
pass
def _calculate_loss(self, batch):
pass
def training_step(self, batch, batch_idx):
pass
def configure_optimizers(self):
raise NotImplementedError