| 98 | |
| 99 | |
| 100 | class PolyLR(object): |
| 101 | def __init__(self, optimizer, curr_iter, max_iter, lr_decay): |
| 102 | self.max_iter = float(max_iter) |
| 103 | self.init_lr_groups = [] |
| 104 | for p in optimizer.param_groups: |
| 105 | self.init_lr_groups.append(p['lr']) |
| 106 | self.param_groups = optimizer.param_groups |
| 107 | self.curr_iter = curr_iter |
| 108 | self.lr_decay = lr_decay |
| 109 | |
| 110 | def step(self): |
| 111 | for idx, p in enumerate(self.param_groups): |
| 112 | p['lr'] = self.init_lr_groups[idx] * (1 - self.curr_iter / self.max_iter) ** self.lr_decay |
| 113 | |
| 114 | |
| 115 | # just a try, not recommend to use |
nothing calls this directly
no outgoing calls
no test coverage detected