Convolutional Model for 2D image data. More...
#include <shark/Models/ConvolutionalModel.h>
Inheritance diagram for shark::Conv2DModel< VectorType, ActivationFunction >:Public Member Functions | |
| Conv2DModel () | |
| Default Constructor; use setStructure later. | |
| Conv2DModel (Shape const &imageShape, Shape const &filterShape, Padding type=Padding::ZeroPad) | |
| Sets the structure by setting the dimensionalities of image and filters. | |
| std::string | name () const |
| returns the name of the object | |
| Shape | inputShape () const |
| Returns the expected shape of the input. | |
| Shape | outputShape () const |
| Returns the shape of the output. | |
| ActivationFunction const & | activationFunction () const |
| Returns the activation function. | |
| ActivationFunction & | activationFunction () |
| Returns the activation function. | |
| ParameterVectorType | parameterVector () const |
| Obtain the parameter vector. | |
| void | setParameterVector (ParameterVectorType const &newParameters) |
| Set the new parameters of the model. | |
| size_t | numberOfParameters () const |
| Return the number of parameters. | |
| void | setStructure (Shape const &imageShape, Shape const &filterShape, Padding type=Padding::ZeroPad) |
| Sets the structure by setting the shape of image and filters. | |
| boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. | |
| void | eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const |
| Evaluate the model. | |
| 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 &derivatives) 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 Features & | features () 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< OutputType > | operator() (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 ¶meterDerivative, 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 |
Convolutional Model for 2D image data.
The image is allowed to have several channels and are linearized to a single vector of size width * height * numChannels. This is done by itnerleaving channels, i.e. for a pixel all channels are stored contiguously. Then the pixels are stored in a row-major scheme.
For handling edge condition, the Conv2D model handles two different convolution modes:
Padding::Valid: The output is only computed on patches which are fully inside the unpadded image as a linearized vector in the same format of size (width - filter_width+1) * (height - filter_height+1) * numFilters.
Padding::ZeroPad The output input is padded with zeros and the output has the same size as the input of size width * height * numFilters.
Definition at line 66 of file ConvolutionalModel.h.
| typedef base_type::BatchInputType shark::Conv2DModel< VectorType, ActivationFunction >::BatchInputType |
Definition at line 76 of file ConvolutionalModel.h.
| typedef base_type::BatchOutputType shark::Conv2DModel< VectorType, ActivationFunction >::BatchOutputType |
Definition at line 75 of file ConvolutionalModel.h.
| typedef base_type::ParameterVectorType shark::Conv2DModel< VectorType, ActivationFunction >::ParameterVectorType |
Definition at line 77 of file ConvolutionalModel.h.
|
inline |
Default Constructor; use setStructure later.
Definition at line 80 of file ConvolutionalModel.h.
References shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< VectorType, VectorType, VectorType >::m_features.
|
inline |
Sets the structure by setting the dimensionalities of image and filters.
Definition at line 90 of file ConvolutionalModel.h.
References shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< VectorType, VectorType, VectorType >::m_features, and shark::Conv2DModel< VectorType, ActivationFunction >::setStructure().
|
inline |
Returns the activation function.
Definition at line 120 of file ConvolutionalModel.h.
|
inline |
Returns the activation function.
Definition at line 115 of file ConvolutionalModel.h.
|
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 162 of file ConvolutionalModel.h.
|
inlinevirtual |
Evaluate the model.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 169 of file ConvolutionalModel.h.
References shark::Conv2DModel< VectorType, ActivationFunction >::inputShape(), shark::Shape::numElements(), shark::Conv2DModel< VectorType, ActivationFunction >::outputShape(), SIZE_CHECK, shark::State::toState(), and shark::Valid.
|
inlinevirtual |
Returns the expected shape of the input.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 102 of file ConvolutionalModel.h.
Referenced by shark::Conv2DModel< VectorType, ActivationFunction >::eval(), shark::Conv2DModel< VectorType, ActivationFunction >::weightedInputDerivative(), and shark::Conv2DModel< VectorType, ActivationFunction >::weightedParameterDerivative().
|
inlinevirtual |
returns the name of the object
Reimplemented from shark::INameable.
Definition at line 98 of file ConvolutionalModel.h.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 138 of file ConvolutionalModel.h.
Referenced by shark::Conv2DModel< VectorType, ActivationFunction >::setParameterVector(), and shark::Conv2DModel< VectorType, ActivationFunction >::weightedParameterDerivative().
|
inlinevirtual |
Returns the shape of the output.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 106 of file ConvolutionalModel.h.
References shark::Valid.
Referenced by shark::Conv2DModel< VectorType, ActivationFunction >::eval(), main(), shark::Conv2DModel< VectorType, ActivationFunction >::weightedInputDerivative(), and shark::Conv2DModel< VectorType, ActivationFunction >::weightedParameterDerivative().
|
inlinevirtual |
Obtain the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 125 of file ConvolutionalModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 281 of file ConvolutionalModel.h.
|
inlinevirtual |
Set the new parameters of the model.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 130 of file ConvolutionalModel.h.
References shark::Conv2DModel< VectorType, ActivationFunction >::numberOfParameters(), and SIZE_CHECK.
|
inline |
Sets the structure by setting the shape of image and filters.
Definition at line 147 of file ConvolutionalModel.h.
Referenced by shark::Conv2DModel< VectorType, ActivationFunction >::Conv2DModel().
|
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 251 of file ConvolutionalModel.h.
References shark::Conv2DModel< VectorType, ActivationFunction >::inputShape(), shark::Conv2DModel< VectorType, ActivationFunction >::outputShape(), SIZE_CHECK, shark::State::toState(), and shark::Valid.
|
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 191 of file ConvolutionalModel.h.
References shark::CHWN, shark::Conv2DModel< VectorType, ActivationFunction >::inputShape(), shark::NHWC, shark::Conv2DModel< VectorType, ActivationFunction >::numberOfParameters(), shark::Conv2DModel< VectorType, ActivationFunction >::outputShape(), SIZE_CHECK, shark::State::toState(), and shark::Valid.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 294 of file ConvolutionalModel.h.