MCPcopy Create free account
hub / github.com/RylonW/DocNLC / BaseModel

Class BaseModel

models/base_model.py:8–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class BaseModel():
9 def __init__(self, opt):
10 self.opt = opt
11 self.device = torch.device('cuda' if opt['gpu_ids'] is not None else 'cpu')
12 self.is_train = opt['is_train']
13 self.schedulers = []
14 self.optimizers = []
15
16 def feed_data(self, data):
17 pass
18
19 def optimize_parameters(self):
20 pass
21
22 def get_current_visuals(self):
23 pass
24
25 def get_current_losses(self):
26 pass
27
28 def print_network(self):
29 pass
30
31 def save(self, label):
32 pass
33
34 def load(self):
35 pass
36
37 def _set_lr(self, lr_groups_l):
38 """Set learning rate for warmup
39 lr_groups_l: list for lr_groups. each for a optimizer"""
40 for optimizer, lr_groups in zip(self.optimizers, lr_groups_l):
41 for param_group, lr in zip(optimizer.param_groups, lr_groups):
42 param_group['lr'] = lr
43
44 def _get_init_lr(self):
45 """Get the initial lr, which is set by the scheduler"""
46 init_lr_groups_l = []
47 for optimizer in self.optimizers:
48 init_lr_groups_l.append([v['initial_lr'] for v in optimizer.param_groups])
49 return init_lr_groups_l
50
51 def update_learning_rate(self, cur_iter, warmup_iter=-1):
52 for scheduler in self.schedulers:
53 scheduler.step()
54 # set up warm-up learning rate
55 if cur_iter < warmup_iter:
56 # get initial lr for each group
57 init_lr_g_l = self._get_init_lr()
58 # modify warming-up learning rates
59 warm_up_lr_l = []
60 for init_lr_g in init_lr_g_l:
61 warm_up_lr_l.append([v / warmup_iter * cur_iter for v in init_lr_g])
62 # set learning rate
63 self._set_lr(warm_up_lr_l)
64
65 def get_current_learning_rate(self):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected