(self, model, input_record, output_dims, weight_init=None,
bias_init=None, weight_optim=None, bias_optim=None, name='fc',
weight_reg=None, bias_reg=None, clip_param=None,
max_fc_size=None, axis=1, transposed=False,
uniform_weight_init_scale_numerator=1.0,
**kwargs)
| 24 | class FC(SamplingTrainableMixin, ModelLayer): |
| 25 | |
| 26 | def __init__(self, model, input_record, output_dims, weight_init=None, |
| 27 | bias_init=None, weight_optim=None, bias_optim=None, name='fc', |
| 28 | weight_reg=None, bias_reg=None, clip_param=None, |
| 29 | max_fc_size=None, axis=1, transposed=False, |
| 30 | uniform_weight_init_scale_numerator=1.0, |
| 31 | **kwargs): |
| 32 | super().__init__(model, name, input_record, **kwargs) |
| 33 | assert isinstance(input_record, schema.Scalar), ( |
| 34 | "Incorrect input type {}".format(input_record)) |
| 35 | assert len(input_record.field_types()[0].shape) > 0, ( |
| 36 | "FC expects limited dimensions of the input tensor") |
| 37 | assert axis >= 1, "axis {} should >= 1.".format(axis) |
| 38 | self.axis = axis |
| 39 | input_dims = np.prod(input_record.field_types()[0].shape[axis - 1:]) |
| 40 | |
| 41 | assert input_dims > 0, ( |
| 42 | "FC expects input dimensions > 0, got {}".format(input_dims)) |
| 43 | |
| 44 | self.clip_args = None |
| 45 | if (clip_param is not None): |
| 46 | assert len(clip_param) == 2, ( |
| 47 | 'clip_param must be a tuple / list ' |
| 48 | 'of length 2 and in the form of (clip_min, clip max)' |
| 49 | ) |
| 50 | clip_min, clip_max = clip_param |
| 51 | assert clip_min is not None or clip_max is not None, ( |
| 52 | 'clip_min, and clip_max in clip_param cannot both be None' |
| 53 | ) |
| 54 | assert ( |
| 55 | (clip_min is None or clip_max is None) or clip_min < clip_max |
| 56 | ), ( |
| 57 | 'clip_param = [clip_min, clip_max] must have clip_min < clip_max' |
| 58 | ) |
| 59 | self.clip_args = {} |
| 60 | if clip_min is not None: |
| 61 | self.clip_args['min'] = clip_min |
| 62 | if clip_max is not None: |
| 63 | self.clip_args['max'] = clip_max |
| 64 | |
| 65 | if uniform_weight_init_scale_numerator is None: |
| 66 | uniform_weight_init_scale_numerator = 1.0 |
| 67 | |
| 68 | scale = math.sqrt(uniform_weight_init_scale_numerator / input_dims) |
| 69 | weight_init = weight_init if weight_init else ( |
| 70 | 'UniformFill', {'min': -scale, 'max': scale}) |
| 71 | bias_init = bias_init if bias_init else ( |
| 72 | 'UniformFill', {'min': -scale, 'max': scale}) |
| 73 | |
| 74 | self.output_dim_vec = FC.calculate_fc_output_dims( |
| 75 | max_fc_size, input_dims, output_dims) |
| 76 | |
| 77 | self.transposed = transposed |
| 78 | if self.output_dim_vec is None or len(self.output_dim_vec) == 1: |
| 79 | weight_shape = [input_dims, output_dims] if transposed else [output_dims, input_dims] |
| 80 | self.w = self.create_param(param_name='w', |
| 81 | shape=weight_shape, |
| 82 | initializer=weight_init, |
| 83 | optimizer=weight_optim, |
nothing calls this directly
no test coverage detected