shark::PoolingLayer< VectorType > Class Template Reference

Performs Pooling operations for a given input image. More...

#include <shark/Models/PoolingLayer.h>

+ Inheritance diagram for shark::PoolingLayer< VectorType >:

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::BatchOutputType BatchOutputType
 
typedef base_type::ParameterVectorType ParameterVectorType
 
- Public Types inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >
enum  Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1 , HAS_FIRST_INPUT_DERIVATIVE = 4 }
 
typedef InputTypeT InputType
 Defines the input type of the model.
 
typedef OutputTypeT OutputType
 Defines the output type of the model.
 
typedef AbstractModel< InputTypeT, OutputTypeT, ParameterVectorTypeModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models.
 
typedef Batch< InputType >::type BatchInputType
 defines the batch type of the input type.
 
typedef Batch< OutputType >::type BatchOutputType
 defines the batch type of the output type
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< VectorType >
typedef VectorType ParameterVectorType
 

Public Member Functions

 PoolingLayer ()
 
 PoolingLayer (Shape const &inputShape, Shape const &patchShape, Pooling pooling=Pooling::Maximum, Padding padding=Padding::Valid)
 
std::string name () const
 From INameable: return the class name.
 
Shape inputShape () const
 Returns the expected shape of the input.
 
Shape outputShape () const
 Returns the shape of the output.
 
ParameterVectorType parameterVector () const
 obtain the parameter vector
 
void setParameterVector (ParameterVectorType const &newParameters)
 overwrite the parameter vector
 
size_t numberOfParameters () const
 returns the number of parameters
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model.
 
void setStructure (Shape const &inputShape, Shape const &patchShape, Pooling type=Pooling::Maximum, Padding padding=Padding::Valid)
 Configures the model.
 
void eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns.
 
void weightedParameterDerivative (BatchInputType const &inputs, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &gradient) const
 Calculates the first derivative w.r.t the parameters and summing them up over all inputs of the last computed batch.
 
void weightedInputDerivative (BatchInputType const &inputs, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 Calculates the first derivative w.r.t the inputs and summs them up over all inputs of the last computed batch.
 
void read (InArchive &archive)
 From ISerializable.
 
void write (OutArchive &archive) const
 From ISerializable.
 
- Public Member Functions inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented.
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented.
 
virtual void eval (BatchInputType const &patterns, BatchOutputType &outputs) const
 Standard interface for evaluating the response of the model to a batch of patterns.
 
virtual void eval (InputType const &pattern, OutputType &output) const
 Standard interface for evaluating the response of the model to a single pattern.
 
Data< OutputTypeoperator() (Data< InputType > const &patterns) const
 Model evaluation as an operator for a whole dataset. This is a convenience function.
 
OutputType operator() (InputType const &pattern) const
 Model evaluation as an operator for a single pattern. This is a convenience function.
 
BatchOutputType operator() (BatchInputType const &patterns) const
 Model evaluation as an operator for a single pattern. This is a convenience function.
 
virtual void weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time
 
- Public Member Functions inherited from shark::IParameterizable< VectorType >
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor.
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...).
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...).
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >
Features m_features
 

Detailed Description

template<class VectorType = RealVector>
class shark::PoolingLayer< VectorType >

Performs Pooling operations for a given input image.

Pooling partitions the input images in rectangular regions, typically 2x2 and computes a statistic over the data. This could for example be the maximum or average of values. This is done channel-by-channel. The output is a smaller image where each pixel includes for each channel the computed statistic. Therefore, if the patch is 2x2 the output image will have half width and height.

Definition at line 56 of file PoolingLayer.h.

Member Typedef Documentation

◆ BatchInputType

template<class VectorType = RealVector>
typedef base_type::BatchInputType shark::PoolingLayer< VectorType >::BatchInputType

Definition at line 61 of file PoolingLayer.h.

◆ BatchOutputType

template<class VectorType = RealVector>
typedef base_type::BatchOutputType shark::PoolingLayer< VectorType >::BatchOutputType

Definition at line 62 of file PoolingLayer.h.

◆ ParameterVectorType

template<class VectorType = RealVector>
typedef base_type::ParameterVectorType shark::PoolingLayer< VectorType >::ParameterVectorType

Definition at line 63 of file PoolingLayer.h.

Constructor & Destructor Documentation

◆ PoolingLayer() [1/2]

◆ PoolingLayer() [2/2]

Member Function Documentation

◆ createState()

template<class VectorType = RealVector>
boost::shared_ptr< State > shark::PoolingLayer< VectorType >::createState ( ) const
inlinevirtual

Creates an internal state of the model.

The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!

Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 103 of file PoolingLayer.h.

◆ eval()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern
stateintermediate results stored by eval which can be reused for derivative computation.

Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 132 of file PoolingLayer.h.

References shark::Maximum, shark::Shape::numElements(), and SIZE_CHECK.

◆ inputShape()

template<class VectorType = RealVector>
Shape shark::PoolingLayer< VectorType >::inputShape ( ) const
inlinevirtual

◆ name()

template<class VectorType = RealVector>
std::string shark::PoolingLayer< VectorType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 77 of file PoolingLayer.h.

◆ numberOfParameters()

template<class VectorType = RealVector>
size_t shark::PoolingLayer< VectorType >::numberOfParameters ( ) const
inlinevirtual

returns the number of parameters

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 99 of file PoolingLayer.h.

◆ outputShape()

template<class VectorType = RealVector>
Shape shark::PoolingLayer< VectorType >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 84 of file PoolingLayer.h.

Referenced by main().

◆ parameterVector()

template<class VectorType = RealVector>
ParameterVectorType shark::PoolingLayer< VectorType >::parameterVector ( ) const
inlinevirtual

obtain the parameter vector

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 89 of file PoolingLayer.h.

◆ read()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::read ( InArchive archive)
inlinevirtual

◆ setParameterVector()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::setParameterVector ( ParameterVectorType const &  newParameters)
inlinevirtual

overwrite the parameter vector

Reimplemented from shark::IParameterizable< VectorType >.

Definition at line 94 of file PoolingLayer.h.

References SIZE_CHECK.

◆ setStructure()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::setStructure ( Shape const &  inputShape,
Shape const &  patchShape,
Pooling  type = Pooling::Maximum,
Padding  padding = Padding::Valid 
)
inline

Configures the model.

  • inputShape Shape of the image imHeight x imWidth x channel
  • outputShape Shape of the resized output imHeight x imWidth
  • type Type of interpolation to perform, default is Spline-Interpolation

Definition at line 112 of file PoolingLayer.h.

References shark::PoolingLayer< VectorType >::inputShape(), SHARK_RUNTIME_CHECK, and shark::Valid.

Referenced by shark::PoolingLayer< VectorType >::PoolingLayer().

◆ weightedInputDerivative()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::weightedInputDerivative ( BatchInputType const &  inputs,
BatchOutputType const &  outputs,
BatchOutputType const &  coefficients,
State const &  state,
BatchInputType derivative 
) const
inlinevirtual

Calculates the first derivative w.r.t the inputs and summs them up over all inputs of the last computed batch.

Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 155 of file PoolingLayer.h.

References shark::Maximum, and SIZE_CHECK.

◆ weightedParameterDerivative()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::weightedParameterDerivative ( BatchInputType const &  inputs,
BatchOutputType const &  outputs,
BatchOutputType const &  coefficients,
State const &  state,
ParameterVectorType gradient 
) const
inlinevirtual

Calculates the first derivative w.r.t the parameters and summing them up over all inputs of the last computed batch.

Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.

Definition at line 143 of file PoolingLayer.h.

References SIZE_CHECK.

◆ write()

template<class VectorType = RealVector>
void shark::PoolingLayer< VectorType >::write ( OutArchive archive) const
inlinevirtual

The documentation for this class was generated from the following file: