MCPcopy Index your code
hub / github.com/TorchSSL/TorchSSL / net_builder

Function net_builder

utils.py:39–75  ·  view source on GitHub ↗

return **class** of backbone network (not instance). Args net_name: 'WideResNet' or network names in torchvision.models from_name: If True, net_buidler takes models in torch.vision models. Then, net_conf is ignored. net_conf: When from_name is False, net_conf is the

(net_name, from_name: bool, net_conf=None, is_remix=False)

Source from the content-addressed store, hash-verified

37
38
39def net_builder(net_name, from_name: bool, net_conf=None, is_remix=False):
40 """
41 return **class** of backbone network (not instance).
42 Args
43 net_name: 'WideResNet' or network names in torchvision.models
44 from_name: If True, net_buidler takes models in torch.vision models. Then, net_conf is ignored.
45 net_conf: When from_name is False, net_conf is the configuration of backbone network (now, only WRN is supported).
46 """
47 if from_name:
48 import torchvision.models as models
49 model_name_list = sorted(name for name in models.__dict__
50 if name.islower() and not name.startswith("__")
51 and callable(models.__dict__[name]))
52
53 if net_name not in model_name_list:
54 assert Exception(f"[!] Networks\' Name is wrong, check net config, \
55 expected: {model_name_list} \
56 received: {net_name}")
57 else:
58 return models.__dict__[net_name]
59
60 else:
61 if net_name == 'WideResNet':
62 import models.nets.wrn as net
63 builder = getattr(net, 'build_WideResNet')()
64 elif net_name == 'WideResNetVar':
65 import models.nets.wrn_var as net
66 builder = getattr(net, 'build_WideResNetVar')()
67 elif net_name == 'ResNet50':
68 import models.nets.resnet50 as net
69 builder = getattr(net, 'build_ResNet50')(is_remix)
70 else:
71 assert Exception("Not Implemented Error")
72
73 if net_name != 'ResNet50':
74 setattr_cls_from_kwargs(builder, net_conf)
75 return builder.build
76
77
78def test_net_builder(net_name, from_name, net_conf=None):

Callers 15

main_workerFunction · 0.90
eval.pyFile · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90
main_workerFunction · 0.90

Calls 1

setattr_cls_from_kwargsFunction · 0.85

Tested by 1

test_net_builderFunction · 0.68