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

Method build

tensorflow/python/keras/layers/convolutional.py:149–198  ·  view source on GitHub ↗
(self, input_shape)

Source from the content-addressed store, hash-verified

147 self.fused = fused
148
149 def build(self, input_shape):
150 input_shape = tensor_shape.TensorShape(input_shape)
151 if self.data_format == 'channels_first':
152 channel_axis = 1
153 else:
154 channel_axis = -1
155 if input_shape.dims[channel_axis].value is None:
156 raise ValueError('The channel dimension of the inputs '
157 'should be defined. Found `None`.')
158 input_dim = int(input_shape[channel_axis])
159 kernel_shape = self.kernel_size + (input_dim, self.filters)
160
161 self.kernel = self.add_weight(
162 name='kernel',
163 shape=kernel_shape,
164 initializer=self.kernel_initializer,
165 regularizer=self.kernel_regularizer,
166 constraint=self.kernel_constraint,
167 trainable=True,
168 dtype=self.dtype)
169 if self.use_bias:
170 self.bias = self.add_weight(
171 name='bias',
172 shape=(self.filters,),
173 initializer=self.bias_initializer,
174 regularizer=self.bias_regularizer,
175 constraint=self.bias_constraint,
176 trainable=True,
177 dtype=self.dtype)
178 else:
179 self.bias = None
180 self.input_spec = InputSpec(ndim=self.rank + 2,
181 axes={channel_axis: input_dim})
182 if self.padding == 'causal':
183 op_padding = 'valid'
184 else:
185 op_padding = self.padding
186 if not isinstance(op_padding, (list, tuple)):
187 op_padding = op_padding.upper()
188
189 self._convolution_op = nn_ops.Convolution(
190 input_shape,
191 filter_shape=self.kernel.shape,
192 dilation_rate=self.dilation_rate,
193 strides=self.strides,
194 padding=op_padding,
195 data_format=conv_utils.convert_data_format(self.data_format,
196 self.rank + 2),
197 fused=self.fused)
198 self.built = True
199
200 def call(self, inputs):
201 outputs = self._convolution_op(inputs, self.kernel)

Callers

nothing calls this directly

Calls 2

InputSpecClass · 0.90
add_weightMethod · 0.45

Tested by

no test coverage detected