9#ifndef CONVOLUTIONALLAYER_H
10#define CONVOLUTIONALLAYER_H
31struct ConvolutionalLayerForwardPropagation;
32struct ConvolutionalLayerBackPropagation;
36class ProbabilisticLayer;
45 enum class ActivationFunction{Threshold, SymmetricThreshold, Logistic, HyperbolicTangent, Linear, RectifiedLinear, ExponentialLinear, ScaledExponentialLinear, SoftPlus, SoftSign, HardSigmoid};
47 enum class ConvolutionType{Valid, Same};
103 void set(
const Tensor<Index, 1>&,
const Tensor<Index, 1>&);
105 void set(
const Tensor<type, 4>&,
const Tensor<type, 4>&,
const Tensor<type, 1>&);
129 void set_parameters_random();
140 const Tensor<type, 2>&,
141 const Tensor<type, 4>&,
142 Tensor<type, 4>&)
const;
148 void calculate_activations_derivatives(
const Tensor<type, 4>&, Tensor<type, 4>&, Tensor<type, 4>&)
const;
154 void forward_propagate(
const Tensor<type, 4>&, LayerForwardPropagation*);
155 void forward_propagate(
const Tensor<type, 2>&, LayerForwardPropagation*);
157 void forward_propagate(
const Tensor<type, 4>&, Tensor<type, 1>, LayerForwardPropagation*);
158 void forward_propagate(
const Tensor<type, 2>&, Tensor<type, 1>, LayerForwardPropagation*);
162 void calculate_hidden_delta(Layer*,
163 LayerForwardPropagation*,
164 const Tensor<type, 2>&,
165 Tensor<type, 2>&)
const;
169 const Tensor<type, 4>&,
170 const Tensor<type, 4>&,
171 const Tensor<type, 4>&,
172 Tensor<type, 2>&)
const;
174 void calculate_hidden_delta_pooling(PoolingLayer*,
175 const Tensor<type, 4>&,
176 const Tensor<type, 4>&,
177 const Tensor<type, 2>&,
178 Tensor<type, 2>&)
const;
181 const Tensor<type, 4>&,
182 const Tensor<type, 2>&,
183 const Tensor<type, 2>&,
184 Tensor<type, 2>&)
const;
186 void calculate_hidden_delta_probabilistic(ProbabilisticLayer*,
187 const Tensor<type, 4>&,
188 const Tensor<type, 4>&,
189 const Tensor<type, 2>&,
190 Tensor<type, 2>&)
const;
194 void calculate_error_gradient(
const Tensor<type, 4>&,
195 LayerForwardPropagation*,
196 LayerBackPropagation&)
const;
198 void calculate_error_gradient(
const Tensor<type, 2>&,
199 LayerForwardPropagation*,
200 LayerBackPropagation&)
const;
202 void insert_gradient(LayerBackPropagation*,
204 Tensor<type, 1>&)
const;
206 void to_2d(
const Tensor<type, 4>&, Tensor<type, 2>&)
const;
219 Index row_stride = 1;
221 Index column_stride = 1;
223 Tensor<Index, 1> input_variables_dimensions;
225 ConvolutionType convolution_type = ConvolutionType::Valid;
230 #include "../../opennn-cuda/opennn-cuda/convolutional_layer_cuda.h"
250 set(new_batch_samples_number, new_layer_pointer);
254 void set(
const Index& new_batch_samples_number,
Layer* new_layer_pointer)
256 layer_pointer = new_layer_pointer;
258 const Index neurons_number = layer_pointer->get_neurons_number();
260 const Index kernels_number =
static_cast<ConvolutionalLayer*
>(layer_pointer)->get_kernels_number();
261 const Index outputs_rows_number =
static_cast<ConvolutionalLayer*
>(layer_pointer)->get_outputs_rows_number();
262 const Index outputs_columns_number =
static_cast<ConvolutionalLayer*
>(layer_pointer)->get_outputs_columns_number();
264 batch_samples_number = new_batch_samples_number;
266 combinations.resize(batch_samples_number, kernels_number, outputs_rows_number, outputs_columns_number);
267 activations.resize(batch_samples_number, kernels_number, outputs_rows_number, outputs_columns_number);
269 activations_derivatives.resize(batch_samples_number, neurons_number, neurons_number, neurons_number);
279 Tensor<type, 4> combinations;
280 Tensor<type, 4> activations;
281 Tensor<type, 4> activations_derivatives;
287 const Index neurons_number = layer_pointer->get_neurons_number();
288 const Index inputs_nmumber = layer_pointer->get_inputs_number();
298 set(new_batch_samples_number, new_layer_pointer);
302 void set(
const Index& new_batch_samples_number,
Layer* new_layer_pointer)
311 Tensor<type, 4> delta;
313 Tensor<type, 4> biases_derivatives;
315 Tensor<type, 4> synaptic_weights_derivatives;
Tensor< Index, 1 > get_input_variables_dimensions() const
Returns the dimension of the input variables.
void set_parameters_constant(const type &)
Index get_synaptic_weights_number() const
Returns the number of layer's synaptic weights.
Index get_column_stride() const
Returns the column stride.
Index get_inputs_number() const
Returns the number of inputs.
Index get_kernels_number() const
Returns the number of kernels of the layer.
Index get_outputs_rows_number() const
Returns the number of rows the result of applying the layer's kernels to an image will have.
void set_biases_constant(const type &)
Tensor< type, 4 > synaptic_weights
This tensor containing conection strengths from a layer's inputs to its neurons.
Index get_inputs_channels_number() const
Returns the number of channels of the input.
Index get_kernels_channels_number() const
Returns the number of channels of the layer's kernels.
ActivationFunction
Enumeration of available activation functions for the convolutional layer.
bool is_empty() const
Returns a boolean, true if convolutional layer is empty and false otherwise.
void set_synaptic_weights(const Tensor< type, 4 > &)
Index get_inputs_rows_number() const
Returns the number of rows of the input.
void set_activation_function(const ActivationFunction &)
Index get_inputs_columns_number() const
Returns the number of columns of the input.
void set_row_stride(const Index &)
void set(const Tensor< Index, 1 > &, const Tensor< Index, 1 > &)
void insert_padding(const Tensor< type, 4 > &, Tensor< type, 4 > &)
const Tensor< type, 1 > & get_biases() const
Returns the layer's biases.
Index get_outputs_columns_number() const
Returns the number of columns the result of applying the layer's kernels to an image will have.
void set_column_stride(const Index &)
Index get_padding_width() const
Returns the total number of columns of zeroes to be added to an image before applying a kernel,...
Index get_neurons_number() const
Returns the number of neurons.
ConvolutionType get_convolution_type() const
Returns the padding option.
void set_biases(const Tensor< type, 1 > &)
Index get_kernels_rows_number() const
Returns the number of rows of the layer's kernels.
Tensor< Index, 1 > get_outputs_dimensions() const
Returns a vector containing the number of channels, rows and columns of the result of applying the la...
void calculate_activations(const Tensor< type, 4 > &, Tensor< type, 4 > &) const
Calculates activations.
ActivationFunction get_activation_function() const
Returns the convolutional layer's activation function.
Index get_row_stride() const
Returns the row stride.
void set_synaptic_weights_constant(const type &)
Index get_padding_height() const
Returns the total number of rows of zeroes to be added to an image before applying a kernel,...
const Tensor< type, 4 > & get_synaptic_weights() const
Returns the layer's synaptic weights.
Index get_kernels_columns_number() const
Returns the number of columns of the layer's kernels.
void set_convolution_type(const ConvolutionType &)
void calculate_convolutions(const Tensor< type, 4 > &, Tensor< type, 4 > &) const
Calculate convolutions.
Index get_parameters_number() const
Returns the number of parameters of the layer.
void calculate_hidden_delta_perceptron(const PerceptronLayer *, const Tensor< type, 4 > &, const Tensor< type, 2 > &, const Tensor< type, 2 > &, Tensor< type, 2 > &) const
void calculate_outputs(const Tensor< type, 4 > &, Tensor< type, 4 > &)
void set_parameters(const Tensor< type, 1 > &, const Index &index)
Tensor< type, 1 > get_parameters() const
Returns the layer's parameters in the form of a vector.
This abstract class represents the concept of layer of neurons in OpenNN.
LayerBackPropagation()
Default constructor.
LayerForwardPropagation()
Default constructor.