MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / build

Method build

tensorflow/python/keras/layers/core.py:1008–1039  ·  view source on GitHub ↗
(self, input_shape)

Source from the content-addressed store, hash-verified

1006 self.input_spec = InputSpec(min_ndim=2)
1007
1008 def build(self, input_shape):
1009 dtype = dtypes.as_dtype(self.dtype or K.floatx())
1010 if not (dtype.is_floating or dtype.is_complex):
1011 raise TypeError('Unable to build `Dense` layer with non-floating point '
1012 'dtype %s' % (dtype,))
1013 input_shape = tensor_shape.TensorShape(input_shape)
1014 if tensor_shape.dimension_value(input_shape[-1]) is None:
1015 raise ValueError('The last dimension of the inputs to `Dense` '
1016 'should be defined. Found `None`.')
1017 last_dim = tensor_shape.dimension_value(input_shape[-1])
1018 self.input_spec = InputSpec(min_ndim=2,
1019 axes={-1: last_dim})
1020 self.kernel = self.add_weight(
1021 'kernel',
1022 shape=[last_dim, self.units],
1023 initializer=self.kernel_initializer,
1024 regularizer=self.kernel_regularizer,
1025 constraint=self.kernel_constraint,
1026 dtype=self.dtype,
1027 trainable=True)
1028 if self.use_bias:
1029 self.bias = self.add_weight(
1030 'bias',
1031 shape=[self.units,],
1032 initializer=self.bias_initializer,
1033 regularizer=self.bias_regularizer,
1034 constraint=self.bias_constraint,
1035 dtype=self.dtype,
1036 trainable=True)
1037 else:
1038 self.bias = None
1039 self.built = True
1040
1041 def call(self, inputs):
1042 rank = len(inputs.shape)

Callers 4

test_count_paramsMethod · 0.95
test_count_paramsMethod · 0.95

Calls 2

InputSpecClass · 0.90
add_weightMethod · 0.45

Tested by 4

test_count_paramsMethod · 0.76
test_count_paramsMethod · 0.76