(config)
| 211 | |
| 212 | |
| 213 | def make_model(config): |
| 214 | dataset_config = config['dataset'] |
| 215 | num_classes = dataset_config['num_classes'] |
| 216 | config = config['model'] |
| 217 | if config['type'] == 'image_v1': |
| 218 | model = models.ImageDenoiserModelV1( |
| 219 | config['input_channels'], |
| 220 | config['mapping_out'], |
| 221 | config['depths'], |
| 222 | config['channels'], |
| 223 | config['self_attn_depths'], |
| 224 | config['cross_attn_depths'], |
| 225 | patch_size=config['patch_size'], |
| 226 | dropout_rate=config['dropout_rate'], |
| 227 | mapping_cond_dim=config['mapping_cond_dim'] + (9 if config['augment_wrapper'] else 0), |
| 228 | unet_cond_dim=config['unet_cond_dim'], |
| 229 | cross_cond_dim=config['cross_cond_dim'], |
| 230 | skip_stages=config['skip_stages'], |
| 231 | has_variance=config['has_variance'], |
| 232 | ) |
| 233 | elif config['type'] == 'image_transformer_v1': |
| 234 | model = models.ImageTransformerDenoiserModelV1( |
| 235 | n_layers=config['depth'], |
| 236 | d_model=config['width'], |
| 237 | d_ff=config['d_ff'], |
| 238 | in_features=config['input_channels'], |
| 239 | out_features=config['input_channels'], |
| 240 | patch_size=config['patch_size'], |
| 241 | num_classes=num_classes + 1 if num_classes else 0, |
| 242 | dropout=config['dropout_rate'], |
| 243 | sigma_data=config['sigma_data'], |
| 244 | ) |
| 245 | elif config['type'] == 'image_transformer_v2': |
| 246 | assert len(config['widths']) == len(config['depths']) |
| 247 | assert len(config['widths']) == len(config['d_ffs']) |
| 248 | assert len(config['widths']) == len(config['self_attns']) |
| 249 | assert len(config['widths']) == len(config['dropout_rate']) |
| 250 | levels = [] |
| 251 | for depth, width, d_ff, self_attn, dropout in zip(config['depths'], config['widths'], config['d_ffs'], config['self_attns'], config['dropout_rate']): |
| 252 | if self_attn['type'] == 'global': |
| 253 | self_attn = models.image_transformer_v2_conditional.GlobalAttentionSpec(self_attn.get('d_head', 64)) |
| 254 | elif self_attn['type'] == 'neighborhood': |
| 255 | self_attn = models.image_transformer_v2_conditional.NeighborhoodAttentionSpec(self_attn.get('d_head', 64), self_attn.get('kernel_size', 7)) |
| 256 | elif self_attn['type'] == 'shifted-window': |
| 257 | self_attn = models.image_transformer_v2_conditional.ShiftedWindowAttentionSpec(self_attn.get('d_head', 64), self_attn['window_size']) |
| 258 | elif self_attn['type'] == 'none': |
| 259 | self_attn = models.image_transformer_v2_conditional.NoAttentionSpec() |
| 260 | else: |
| 261 | raise ValueError(f'unsupported self attention type {self_attn["type"]}') |
| 262 | levels.append(models.image_transformer_v2_conditional.LevelSpec(depth, width, d_ff, self_attn, dropout)) |
| 263 | mapping = models.image_transformer_v2_conditional.MappingSpec(config['mapping_depth'], config['mapping_width'], config['mapping_d_ff'], config['mapping_dropout_rate']) |
| 264 | model = models.ImageTransformerDenoiserModelV2( |
| 265 | levels=levels, |
| 266 | mapping=mapping, |
| 267 | in_channels=config['input_channels'], |
| 268 | out_channels=config['input_channels'], |
| 269 | patch_size=config['patch_size'], |
| 270 | num_classes=num_classes + 1 if num_classes else 0, |
nothing calls this directly
no outgoing calls
no test coverage detected