OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::DropoutOp Struct Reference

Inverted dropout: at training time zeros activations with probability rate and rescales survivors. More...

#include <operators.h>

Inheritance diagram for opennn::DropoutOp:
[legend]

Public Member Functions

bool active () const
 Returns true when the dropout rate is non-zero.
 
void set_rate (float new_rate)
 Sets the drop probability (0 disables dropout).
 
void forward_propagate (ForwardPropagation &fp, size_t layer, bool is_training) noexcept override
 Runs the operator's forward computation.
 
void back_propagate (ForwardPropagation &fp, BackPropagation &bp, size_t layer) const noexcept override
 Runs the operator's backward computation, accumulating into gradient/delta buffers.
 
void apply_cpu (TensorView &output)
 CPU forward implementation; samples the mask and rescales survivors in place.
 
void apply_gpu (TensorView &output)
 GPU forward implementation; samples the mask and rescales survivors in place.
 
void apply_delta (TensorView &delta) const
 Applies the cached mask to a gradient tensor during the backward pass.
 
void to_JSON (JsonWriter &w) const override
 Serializes the operator configuration to a JSON writer.
 
void from_JSON (const Json *parent) override
 Restores the operator configuration from a JSON node.
 
void destroy_cuda () override
 Releases CUDA resources owned by the operator; called from destructors.
 
 ~DropoutOp () override
 
 DropoutOp ()=default
 
 DropoutOp (DropoutOp &&) noexcept=default
 
DropoutOpoperator= (DropoutOp &&) noexcept=default
 
- Public Member Functions inherited from opennn::Operator
virtual ~Operator ()=default
 
virtual vector< TensorSpecparameter_specs () const
 Returns the tensor specs of trainable parameters owned by this operator.
 
virtual vector< TensorSpecstate_specs () const
 Returns the tensor specs of persistent state owned by this operator.
 
virtual void link_parameters (span< const TensorView >)
 Binds parameter views provided by the hosting layer.
 
virtual void link_gradients (span< const TensorView >)
 Binds gradient views provided by the hosting layer.
 
virtual void link_states (span< const TensorView >)
 Binds state views provided by the hosting layer.
 
virtual void set_parameters_random ()
 Initializes parameters with random values.
 
virtual void set_parameters_glorot ()
 Initializes parameters using Glorot (Xavier) initialization.
 
virtual void load_state_from_JSON (const Json *)
 Restores persistent state (e.g. running statistics) from a JSON node.
 
TensorViewget_input (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
vector< TensorView > & get_inputs (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_output (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_output_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_input_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept
 

Public Attributes

float rate = 0.0f
 
Buffer mask
 
vector< size_t > save_slots
 
- Public Attributes inherited from opennn::Operator
vector< size_t > input_slots = {0}
 
vector< size_t > output_slots = {1}
 
vector< size_t > input_delta_slots = {1}
 
vector< size_t > output_delta_slots = {0}
 

Detailed Description

Inverted dropout: at training time zeros activations with probability rate and rescales survivors.

Constructor & Destructor Documentation

◆ ~DropoutOp()

opennn::DropoutOp::~DropoutOp ( )
inlineoverride

◆ DropoutOp() [1/2]

opennn::DropoutOp::DropoutOp ( )
default

◆ DropoutOp() [2/2]

opennn::DropoutOp::DropoutOp ( DropoutOp && )
defaultnoexcept

Member Function Documentation

◆ active()

bool opennn::DropoutOp::active ( ) const
inline

Returns true when the dropout rate is non-zero.

◆ apply_cpu()

void opennn::DropoutOp::apply_cpu ( TensorView & output)

CPU forward implementation; samples the mask and rescales survivors in place.

◆ apply_delta()

void opennn::DropoutOp::apply_delta ( TensorView & delta) const

Applies the cached mask to a gradient tensor during the backward pass.

◆ apply_gpu()

void opennn::DropoutOp::apply_gpu ( TensorView & output)

GPU forward implementation; samples the mask and rescales survivors in place.

◆ back_propagate()

void opennn::DropoutOp::back_propagate ( ForwardPropagation & fp,
BackPropagation & bp,
size_t layer ) const
overridevirtualnoexcept

Runs the operator's backward computation, accumulating into gradient/delta buffers.

Parameters
fpForward propagation workspace (read-only).
bpBack propagation workspace receiving gradients and deltas.
layerIndex of the hosting layer in the workspace.

Reimplemented from opennn::Operator.

◆ destroy_cuda()

void opennn::DropoutOp::destroy_cuda ( )
overridevirtual

Releases CUDA resources owned by the operator; called from destructors.

Reimplemented from opennn::Operator.

◆ forward_propagate()

void opennn::DropoutOp::forward_propagate ( ForwardPropagation & fp,
size_t layer,
bool is_training )
overridevirtualnoexcept

Runs the operator's forward computation.

Parameters
fpForward propagation workspace.
layerIndex of the hosting layer in the workspace.
is_trainingIf true, enables training-only behavior (e.g. dropout sampling).

Reimplemented from opennn::Operator.

◆ from_JSON()

void opennn::DropoutOp::from_JSON ( const Json * )
overridevirtual

Restores the operator configuration from a JSON node.

Reimplemented from opennn::Operator.

◆ operator=()

DropoutOp & opennn::DropoutOp::operator= ( DropoutOp && )
defaultnoexcept

◆ set_rate()

void opennn::DropoutOp::set_rate ( float new_rate)

Sets the drop probability (0 disables dropout).

◆ to_JSON()

void opennn::DropoutOp::to_JSON ( JsonWriter & ) const
overridevirtual

Serializes the operator configuration to a JSON writer.

Reimplemented from opennn::Operator.

Member Data Documentation

◆ mask

Buffer opennn::DropoutOp::mask

◆ rate

float opennn::DropoutOp::rate = 0.0f

◆ save_slots

vector<size_t> opennn::DropoutOp::save_slots