Caffe2 - Python API
A deep learning, cross platform ML framework
elementwise_linear.py
1 ## @package elementwise_linear
2 # Module caffe2.python.helpers.elementwise_linear
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 
8 from caffe2.python import core
9 from caffe2.python.modeling.parameter_info import ParameterTags
10 
11 
12 def _elementwise_linear(
13  model, op_call, blob_in, blob_out, dim,
14  weight_init=None, bias_init=None, **kwargs
15 ):
16  """Elementwise_Linear"""
17  weight_init = weight_init or ('ConstantFill', {'value': 1.0})
18  bias_init = bias_init or ('ConstantFill', {'value': 0.0})
19  blob_out = blob_out or model.net.NextName()
20  if model.init_params:
21  weight = model.param_init_net.__getattr__(weight_init[0])(
22  [],
23  blob_out + '_w',
24  shape=[dim],
25  **weight_init[1]
26  )
27  bias = model.param_init_net.__getattr__(bias_init[0])(
28  [],
29  blob_out + '_b',
30  shape=[dim],
31  **bias_init[1]
32  )
33  else:
34  weight = core.ScopedBlobReference(
35  blob_out + '_w', model.param_init_net)
36  bias = core.ScopedBlobReference(
37  blob_out + '_b', model.param_init_net)
38 
39  model.AddParameter(weight, ParameterTags.WEIGHT)
40  model.AddParameter(bias, ParameterTags.BIAS)
41  return op_call([blob_in, weight, bias], blob_out, **kwargs)
42 
43 
44 def elementwise_linear(model, *args, **kwargs):
45  return _elementwise_linear(
46  model, model.net.ElementwiseLinear, *args, **kwargs)
Module caffe2.python.helpers.elementwise_linear.