-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy path__init__.py
More file actions
54 lines (43 loc) · 1.26 KB
/
__init__.py
File metadata and controls
54 lines (43 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Network Initializations
"""
import importlib
import torch
from runx.logx import logx
from config import cfg
def get_net(args, criterion):
"""
Get Network Architecture based on arguments provided
"""
net = get_model(network='network.' + args.arch,
num_classes=cfg.DATASET.NUM_CLASSES,
criterion=criterion)
num_params = sum([param.nelement() for param in net.parameters()])
logx.msg('Model params = {:2.1f}M'.format(num_params / 1000000))
net = net.cuda()
return net
def is_gscnn_arch(args):
"""
Network is a GSCNN network
"""
return 'gscnn' in args.arch
def wrap_network_in_dataparallel(net, use_apex_data_parallel=False):
"""
Wrap the network in Dataparallel
"""
if use_apex_data_parallel:
import apex
net = apex.parallel.DistributedDataParallel(net)
else:
net = torch.nn.DataParallel(net)
return net
def get_model(network, num_classes, criterion):
"""
Fetch Network Function Pointer
"""
module = network[:network.rfind('.')]
model = network[network.rfind('.') + 1:]
mod = importlib.import_module(module)
net_func = getattr(mod, model)
net = net_func(num_classes=num_classes, criterion=criterion)
return net