OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::ConvolutionalRelu Class Referencefinal

Fused convolution + ReLU layer; runs as a single GPU op (cudnn) and is CUDA-Graph friendly. More...

#include <convolutional_relu_layer.h>

Inheritance diagram for opennn::ConvolutionalRelu:
[legend]

Public Member Functions

 ConvolutionalRelu (const Shape &={3, 3, 1}, const Shape &={3, 3, 1, 1}, const Shape &={1, 1}, const string &="Valid", const string &="convolutional_relu_layer")
 Constructs a fused convolution+ReLU layer.
 
Shape get_input_shape () const override
 Returns the input tensor shape (height, width, channels).
 
Shape get_output_shape () const override
 Returns the output tensor shape after the fused conv+ReLU.
 
Index get_output_height () const
 Returns the output feature map height.
 
Index get_output_width () const
 Returns the output feature map width.
 
Index get_input_height () const
 
Index get_input_width () const
 
Index get_input_channels () const
 
Index get_kernel_height () const
 
Index get_kernel_width () const
 
Index get_kernel_channels () const
 
Index get_kernels_number () const
 
Index get_row_stride () const
 
Index get_column_stride () const
 
pair< Index, Index > get_padding () const
 
Index get_padding_height () const
 Returns the padding applied along the height axis.
 
Index get_padding_width () const
 Returns the padding applied along the width axis.
 
bool get_use_padding () const
 
ActivationOp::Function get_output_activation () const override
 Returns the layer's output activation (Identity for most layers; overridden by Dense/Bounding).
 
void set (const Shape &={0, 0, 0}, const Shape &={3, 3, 1, 1}, const Shape &={1, 1}, const string &="Valid", const string &="convolutional_relu_layer")
 Reconfigures the layer with new shapes and convolution settings.
 
void set_input_shape (const Shape &) override
 Updates the layer for a new input shape and reinitializes derived sizes.
 
void on_compute_dtype_changed () override
 Rebuilds the fused convolution operator when the compute dtype changes.
 
void set_row_stride (const Index)
 
void set_column_stride (const Index)
 
void set_convolution_type (const string &)
 Sets convolution type ("Valid" or "Same") and updates padding.
 
void read_JSON_body (const Json *) override
 Reads the layer configuration from a JSON node.
 
void write_JSON_body (JsonWriter &) const override
 Writes the layer configuration to a JSON writer.
 
- Public Member Functions inherited from opennn::Layer
virtual ~Layer ()=default
 
const string & get_label () const
 
const string & get_name () const
 
LayerType get_type () const
 
virtual void set_output_shape (const Shape &)
 Sets the output shape; subclasses override when the output is user-configurable.
 
void set_label (string new_label)
 
Index get_parameters_number () const
 Returns the total number of trainable parameters owned by this layer.
 
const vector< Operator * > & get_operators () const
 
virtual vector< TensorSpecget_parameter_specs () const
 Returns the tensor specs of trainable parameters; subclasses override.
 
virtual vector< TensorSpecget_state_specs () const
 Returns the tensor specs of persistent state (e.g. running mean/variance).
 
virtual vector< TensorSpecget_forward_specs (Index batch_size) const
 Returns the tensor specs of the forward workspace; defaults to a single output tensor.
 
virtual vector< TensorSpecget_backward_specs (Index batch_size) const
 Returns the tensor specs of the backward workspace; empty for non-trainable layers.
 
Index get_inputs_number () const
 
Index get_outputs_number () const
 
virtual void forward_propagate (ForwardPropagation &fp, size_t layer, bool is_training) noexcept
 Runs the forward pass by chaining the layer's operators in order.
 
virtual void back_propagate (ForwardPropagation &fp, BackPropagation &bp, size_t i) const noexcept
 Runs the backward pass by chaining the layer's operators in reverse order.
 
virtual void from_JSON (const JsonDocument &document)
 Restores layer configuration and parameters from a JSON document.
 
virtual void load_state_from_JSON (const JsonDocument &document)
 Restores persistent state (e.g. running statistics) from a JSON document.
 
virtual void to_JSON (JsonWriter &writer) const
 Serializes layer configuration and parameters to a JSON writer.
 
virtual string write_expression (const vector< string > &, const vector< string > &) const
 Returns a human-readable mathematical expression for this layer (empty by default).
 
virtual void print () const
 Prints a human-readable summary of the layer to standard output.
 
bool get_is_trainable () const
 
Type get_compute_dtype () const
 
void set_compute_dtype (Type new_compute_dtype)
 Sets the compute dtype and notifies subclasses via on_compute_dtype_changed().
 
virtual float * link_states (float *pointer)
 Binds the persistent-state region of the shared buffer to operator views.
 
float * link_gradients (float *pointer, vector< TensorView > &gradient_views)
 Binds the gradient slice of the shared buffer to operator gradient views.
 
vector< TensorView > & get_parameter_views ()
 
const vector< TensorView > & get_parameter_views () const
 
void redistribute_parameters_to_operators ()
 Re-binds operator parameter views after the parameter buffer has been resized or moved.
 

Additional Inherited Members

- Protected Types inherited from opennn::Layer
enum  Forward { Input , Output }
 
enum  Backward { OutputDelta , InputDelta }
 
- Protected Member Functions inherited from opennn::Layer
 Layer ()=default
 
 Layer (LayerType t, bool trainable=true)
 
float * link_views_to_operators (vector< TensorView > &views, float *pointer, vector< TensorSpec >(Operator::*specs_fn)() const, void(Operator::*link_fn)(span< const TensorView >))
 
- Protected Attributes inherited from opennn::Layer
string label = "my_layer"
 
LayerType layer_type = LayerType::Dense
 
bool is_trainable = true
 
Shape input_shape
 
Type compute_dtype = Type::FP32
 
vector< TensorViewparameters
 
vector< TensorViewstates
 
vector< Operator * > operators
 

Detailed Description

Fused convolution + ReLU layer; runs as a single GPU op (cudnn) and is CUDA-Graph friendly.

Constructor & Destructor Documentation

◆ ConvolutionalRelu()

opennn::ConvolutionalRelu::ConvolutionalRelu ( const Shape & = {3, 3, 1},
const Shape & = {3, 3, 1, 1},
const Shape & = {1, 1},
const string & = "Valid",
const string & = "convolutional_relu_layer" )

Constructs a fused convolution+ReLU layer.

Parameters
input_shapeShape of the input tensor (height, width, channels).
kernel_shapeShape of the convolution kernel (height, width, channels, kernels).
stride_shapeStride along height and width.
convolution_type"Valid" or "Same" padding.
nameLayer name used for serialization.

Member Function Documentation

◆ get_column_stride()

Index opennn::ConvolutionalRelu::get_column_stride ( ) const
inline

◆ get_input_channels()

Index opennn::ConvolutionalRelu::get_input_channels ( ) const
inline

◆ get_input_height()

Index opennn::ConvolutionalRelu::get_input_height ( ) const
inline

◆ get_input_shape()

Shape opennn::ConvolutionalRelu::get_input_shape ( ) const
inlineoverridevirtual

Returns the input tensor shape (height, width, channels).

Reimplemented from opennn::Layer.

◆ get_input_width()

Index opennn::ConvolutionalRelu::get_input_width ( ) const
inline

◆ get_kernel_channels()

Index opennn::ConvolutionalRelu::get_kernel_channels ( ) const
inline

◆ get_kernel_height()

Index opennn::ConvolutionalRelu::get_kernel_height ( ) const
inline

◆ get_kernel_width()

Index opennn::ConvolutionalRelu::get_kernel_width ( ) const
inline

◆ get_kernels_number()

Index opennn::ConvolutionalRelu::get_kernels_number ( ) const
inline

◆ get_output_activation()

ActivationOp::Function opennn::ConvolutionalRelu::get_output_activation ( ) const
inlineoverridevirtual

Returns the layer's output activation (Identity for most layers; overridden by Dense/Bounding).

Reimplemented from opennn::Layer.

◆ get_output_height()

Index opennn::ConvolutionalRelu::get_output_height ( ) const

Returns the output feature map height.

◆ get_output_shape()

Shape opennn::ConvolutionalRelu::get_output_shape ( ) const
overridevirtual

Returns the output tensor shape after the fused conv+ReLU.

Implements opennn::Layer.

◆ get_output_width()

Index opennn::ConvolutionalRelu::get_output_width ( ) const

Returns the output feature map width.

◆ get_padding()

pair< Index, Index > opennn::ConvolutionalRelu::get_padding ( ) const
inline

◆ get_padding_height()

Index opennn::ConvolutionalRelu::get_padding_height ( ) const

Returns the padding applied along the height axis.

◆ get_padding_width()

Index opennn::ConvolutionalRelu::get_padding_width ( ) const

Returns the padding applied along the width axis.

◆ get_row_stride()

Index opennn::ConvolutionalRelu::get_row_stride ( ) const
inline

◆ get_use_padding()

bool opennn::ConvolutionalRelu::get_use_padding ( ) const
inline

◆ on_compute_dtype_changed()

void opennn::ConvolutionalRelu::on_compute_dtype_changed ( )
inlineoverridevirtual

Rebuilds the fused convolution operator when the compute dtype changes.

Reimplemented from opennn::Layer.

◆ read_JSON_body()

void opennn::ConvolutionalRelu::read_JSON_body ( const Json * )
overridevirtual

Reads the layer configuration from a JSON node.

Reimplemented from opennn::Layer.

◆ set()

void opennn::ConvolutionalRelu::set ( const Shape & = {0, 0, 0},
const Shape & = {3, 3, 1, 1},
const Shape & = {1, 1},
const string & = "Valid",
const string & = "convolutional_relu_layer" )

Reconfigures the layer with new shapes and convolution settings.

◆ set_column_stride()

void opennn::ConvolutionalRelu::set_column_stride ( const Index )

◆ set_convolution_type()

void opennn::ConvolutionalRelu::set_convolution_type ( const string & )

Sets convolution type ("Valid" or "Same") and updates padding.

◆ set_input_shape()

void opennn::ConvolutionalRelu::set_input_shape ( const Shape & )
overridevirtual

Updates the layer for a new input shape and reinitializes derived sizes.

Reimplemented from opennn::Layer.

◆ set_row_stride()

void opennn::ConvolutionalRelu::set_row_stride ( const Index )

◆ write_JSON_body()

void opennn::ConvolutionalRelu::write_JSON_body ( JsonWriter & ) const
overridevirtual

Writes the layer configuration to a JSON writer.

Reimplemented from opennn::Layer.