MCPcopy Create free account
hub / github.com/SooLab/CGFormer / build_model

Function build_model

model/__init__.py:7–57  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

5
6
7def build_model(args):
8 # initialize the SwinTransformer backbone with the specified version
9 if args.swin_type == 'tiny':
10 embed_dim = 96
11 depths = [2, 2, 6, 2]
12 num_heads = [3, 6, 12, 24]
13 elif args.swin_type == 'small':
14 embed_dim = 96
15 depths = [2, 2, 18, 2]
16 num_heads = [3, 6, 12, 24]
17 elif args.swin_type == 'base':
18 embed_dim = 128
19 depths = [2, 2, 18, 2]
20 num_heads = [4, 8, 16, 32]
21 elif args.swin_type == 'large':
22 embed_dim = 192
23 depths = [2, 2, 18, 2]
24 num_heads = [6, 12, 24, 48]
25 else:
26 assert False
27 # args.window12 added for test.py because state_dict is loaded after model initialization
28 if 'window12' in args.swin_pretrain or args.window12:
29 logger.info('Window size 12!')
30 window_size = 12
31 else:
32 window_size = 7
33
34 if args.mha:
35 mha = args.mha.split('-') # if non-empty, then ['a', 'b', 'c', 'd']
36 mha = [int(a) for a in mha]
37 else:
38 mha = [1, 1, 1, 1]
39
40 out_indices = (0, 1, 2, 3)
41 backbone = MultiModalSwinTransformer(embed_dim=embed_dim, depths=depths, num_heads=num_heads,
42 window_size=window_size,
43 ape=False, drop_path_rate=0.3, patch_norm=True,
44 out_indices=out_indices,
45 use_checkpoint=False, num_heads_fusion=mha,
46 fusion_drop=args.fusion_drop
47 )
48 if args.swin_pretrain:
49 logger.info('Initializing Multi-modal Swin Transformer weights from ' + args.swin_pretrain)
50 backbone.init_weights(pretrained=args.swin_pretrain)
51 else:
52 logger.info('Randomly initialize Multi-modal Swin Transformer weights.')
53 backbone.init_weights()
54
55 model = CGFormer(backbone, args)
56
57 return model
58
59
60def build_segmenter(args, DDP=True, OPEN=False):

Callers 1

build_segmenterFunction · 0.85

Calls 3

init_weightsMethod · 0.95
CGFormerClass · 0.85

Tested by

no test coverage detected