-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
43 lines (30 loc) · 1.04 KB
/
models.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
import torch
models = {}
def register(name):
def decorator(cls):
models[name] = cls
return cls
return decorator
def make(name, **kwargs):
if name is None:
return None
model = models[name](**kwargs)
if torch.cuda.is_available():
model.cuda()
return model
def load(model_sv, name=None):#, test_model=None):
if name is None:
name = 'model'
# if test_model is not None:
# model = make(test_model, **model_sv[name + '_args'])
# else:
for key in ['train', 'test', 'val']:
if model_sv['config'].get(f"{key}_dataset") in ['cifarfs', 'fc100'] and 'resnet' in model_sv['model_args']['encoder']:
model_sv[name + '_args']['encoder_args']['dropblock_size'] = 2
break
model = make(model_sv[name], **model_sv[name + '_args'])
# if not test_model:
model.load_state_dict(model_sv[name + '_sd'])#, strict=False)
# elif test_model is not None:
# model.load_state_dict(model_sv[name + '_sd'], strict=False)
return model