MCPcopy Index your code
hub / github.com/pytorch/pytorch / ModelHelper

Class ModelHelper

caffe2/python/model_helper.py:75–491  ·  view source on GitHub ↗

A helper model so we can manange models more easily. It contains net def and parameter storages. You can add an Operator yourself, e.g. model = model_helper.ModelHelper(name="train_net") # init your weight and bias as w and b w = model.param_init_net.XavierFill(...)

Source from the content-addressed store, hash-verified

73
74
75class ModelHelper:
76 """A helper model so we can manange models more easily. It contains net def
77 and parameter storages. You can add an Operator yourself, e.g.
78
79 model = model_helper.ModelHelper(name="train_net")
80 # init your weight and bias as w and b
81 w = model.param_init_net.XavierFill(...)
82 b = model.param_init_net.ConstantFill(...)
83 fc1 = model.FC([input, w, b], output, **kwargs)
84
85 or you can use helper functions in brew module without manually
86 defining parameter initializations and operators.
87
88 model = model_helper.ModelHelper(name="train_net")
89 fc1 = brew.fc(model, input, output, dim_in, dim_out, **kwargs)
90
91 """
92
93 def __init__(self, name=None, init_params=True, allow_not_known_ops=True,
94 skip_sparse_optim=False, param_model=None, arg_scope=None):
95 self.name = name or "model"
96 self.net = core.Net(self.name)
97
98 if param_model is not None:
99 self.param_init_net = param_model.param_init_net
100 self.param_to_grad = param_model.param_to_grad
101 self.params = param_model.params
102 self._parameters_info = param_model._parameters_info
103 self._computed_params = param_model._computed_params
104 else:
105 self.param_init_net = core.Net(self.name + '_init')
106 self.param_to_grad = {}
107 self.params = []
108 self._parameters_info = {}
109 self._computed_params = []
110
111 self._param_info_deprecated = []
112 self._devices = []
113 self.gradient_ops_added = False
114 self.init_params = init_params
115 self.allow_not_known_ops = allow_not_known_ops
116 self.skip_sparse_optim = skip_sparse_optim
117 self.weights = []
118 self.biases = []
119 self._arg_scope = {
120 'order': "NCHW",
121 'use_cudnn': True,
122 'cudnn_exhaustive_search': False,
123 }
124 if arg_scope is not None:
125 # Please notice value as None is not acceptable. We are not checking it
126 # here because we already have check in MakeArgument.
127 self._arg_scope.update(arg_scope)
128
129 @property
130 def arg_scope(self):
131 return self._arg_scope
132

Callers 15

test_helperMethod · 0.90
mainFunction · 0.90
allcompare_processFunction · 0.90
setUpMethod · 0.90
test_dropoutMethod · 0.90
test_fcMethod · 0.90
test_reluMethod · 0.90
test_tanhMethod · 0.90
test_validateMethod · 0.90
test_arg_scope_singleMethod · 0.90
test_model_helperMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_helperMethod · 0.72
allcompare_processFunction · 0.72
setUpMethod · 0.72
test_dropoutMethod · 0.72
test_fcMethod · 0.72
test_reluMethod · 0.72
test_tanhMethod · 0.72
test_validateMethod · 0.72
test_arg_scope_singleMethod · 0.72
test_model_helperMethod · 0.72
test_get_paramsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…