3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
15 def __init__(self, model, input_record, bias_init=None,
16 bias_optim=
None, name=
'add_bias'):
17 super(AddBias, self).__init__(model, name, input_record)
18 assert isinstance(input_record,
schema.Scalar),
"Incorrect input type" 19 assert len(input_record.field_type().shape) > 0, (
20 "AddBias expects limited dimensions of the input tensor")
22 input_dims = input_record.field_type().shape[0]
23 assert input_dims > 0, (
24 "AddBias expects input dimensions > 0, got {}".format(input_dims))
26 scale = math.sqrt(1.0 / input_dims)
27 bias_init = bias_init
if bias_init
else (
28 'UniformFill', {
'min': -scale,
'max': scale})
33 initializer=bias_init,
38 (input_record.field_type().base, (input_dims, )),
42 def add_ops(self, net):
43 net.Add(self.input_record.field_blobs() + [self.
b],
44 self.output_schema.field_blobs(), broadcast=1)
def get_next_blob_reference(self, name)
def create_param(self, param_name, shape, initializer, optimizer, ps_param=None, regularizer=None)