(weight_group, module, lr)
| 167 | |
| 168 | |
| 169 | def group_weight(weight_group, module, lr): |
| 170 | group_decay = [] |
| 171 | group_no_decay = [] |
| 172 | for m in module.modules(): |
| 173 | if isinstance(m, nn.Linear): |
| 174 | group_decay.append(m.weight) |
| 175 | if m.bias is not None: |
| 176 | group_no_decay.append(m.bias) |
| 177 | elif isinstance(m, nn.modules.conv._ConvNd): |
| 178 | group_decay.append(m.weight) |
| 179 | if m.bias is not None: |
| 180 | group_no_decay.append(m.bias) |
| 181 | elif isinstance(m, nn.modules.batchnorm._BatchNorm): |
| 182 | if m.weight is not None: |
| 183 | group_no_decay.append(m.weight) |
| 184 | if m.bias is not None: |
| 185 | group_no_decay.append(m.bias) |
| 186 | assert len(list( |
| 187 | module.parameters())) == len(group_decay) + len(group_no_decay) |
| 188 | weight_group.append(dict(params=group_decay, lr=lr)) |
| 189 | weight_group.append(dict(params=group_no_decay, weight_decay=.0, lr=lr)) |
| 190 | return weight_group |
| 191 | |
| 192 | |
| 193 | def colorize(gray, palette): |
nothing calls this directly
no outgoing calls
no test coverage detected