Logo ROOT   6.18/05
Reference Guide
ConvLayer.h
Go to the documentation of this file.
1// @(#)root/tmva/tmva/dnn:$Id$
2// Author: Vladimir Ilievski
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : TConvLayer *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Convolutional Deep Neural Network Layer *
12 * *
13 * Authors (alphabetical): *
14 * Vladimir Ilievski <ilievski.vladimir@live.com> - CERN, Switzerland *
15 * *
16 * Copyright (c) 2005-2015: *
17 * CERN, Switzerland *
18 * U. of Victoria, Canada *
19 * MPI-K Heidelberg, Germany *
20 * U. of Bonn, Germany *
21 * *
22 * Redistribution and use in source and binary forms, with or without *
23 * modification, are permitted according to the terms listed in LICENSE *
24 * (http://tmva.sourceforge.net/LICENSE) *
25 **********************************************************************************/
26
27#ifndef TMVA_CNN_CONVLAYER
28#define TMVA_CNN_CONVLAYER
29
30#include "TMatrix.h"
31
33#include "TMVA/DNN/Functions.h"
34
35#include <vector>
36#include <iostream>
37
38namespace TMVA {
39namespace DNN {
40namespace CNN {
41
42template <typename Architecture_t>
43class TConvLayer : public VGeneralLayer<Architecture_t> {
44public:
45 using Matrix_t = typename Architecture_t::Matrix_t;
46 using Scalar_t = typename Architecture_t::Scalar_t;
47
48private:
49 /* Calculate the output dimension of the convolutional layer */
50 size_t calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride);
51
52 /* Calculate the number of pixels in a single receptive field */
53 size_t inline calculateNLocalViewPixels(size_t depth, size_t height, size_t width) { return depth * height * width; }
54
55 /* Calculate the number of receptive fields in an image given the filter and image sizes */
56 size_t calculateNLocalViews(size_t inputHeight, size_t filterHeight, size_t paddingHeight, size_t strideRows,
57 size_t inputWidth, size_t filterWidth, size_t paddingWidth, size_t strideCols);
58
59protected:
60 size_t fFilterDepth; ///< The depth of the filter.
61 size_t fFilterHeight; ///< The height of the filter.
62 size_t fFilterWidth; ///< The width of the filter.
63
64 size_t fStrideRows; ///< The number of row pixels to slid the filter each step.
65 size_t fStrideCols; ///< The number of column pixels to slid the filter each step.
66
67 size_t fNLocalViewPixels; ///< The number of pixels in one local image view.
68 size_t fNLocalViews; ///< The number of local views in one image.
69
70 Scalar_t fDropoutProbability; ///< Probability that an input is active.
71
72private:
73 size_t fPaddingHeight; ///< The number of zero layers added top and bottom of the input.
74 size_t fPaddingWidth; ///< The number of zero layers left and right of the input.
75
76 std::vector<Matrix_t> fDerivatives; ///< First fDerivatives of the activations of this layer.
77
78 std::vector<int> fBackwardIndices; ///< Vector of indices used for a fast Im2Col in backward pass
79
80 EActivationFunction fF; ///< Activation function of the layer.
81 ERegularization fReg; ///< The regularization method.
82 Scalar_t fWeightDecay; ///< The weight decay.
83
84 std::vector<Matrix_t> fForwardMatrices; ///< Vector of matrices used for speeding-up the forward pass.
85
86public:
87 /*! Constructor. */
88 TConvLayer(size_t BatchSize, size_t InputDepth, size_t InputHeight, size_t InputWidth, size_t Depth, EInitialization Init,
89 size_t FilterHeight, size_t FilterWidth, size_t StrideRows, size_t StrideCols, size_t PaddingHeight,
90 size_t PaddingWidth, Scalar_t DropoutProbability, EActivationFunction f, ERegularization Reg,
91 Scalar_t WeightDecay);
92
93 /*! Copy the conv layer provided as a pointer */
95
96 /*! Copy constructor. */
97 TConvLayer(const TConvLayer &);
98
99 /*! Destructor. */
100 ~TConvLayer();
101
102 /*! Computes activation of the layer for the given input. The input
103 * must be in 3D tensor form with the different matrices corresponding to
104 * different events in the batch. Computes activations as well as
105 * the first partial derivative of the activation function at those
106 * activations. */
107 void Forward(std::vector<Matrix_t> &input, bool applyDropout = false);
108
109 /*! Compute weight, bias and activation gradients. Uses the precomputed
110 * first partial derviatives of the activation function computed during
111 * forward propagation and modifies them. Must only be called directly
112 * at the corresponding call to Forward(...). */
113 void Backward(std::vector<Matrix_t> &gradients_backward, const std::vector<Matrix_t> &activations_backward,
114 std::vector<Matrix_t> &inp1, std::vector<Matrix_t> &inp2);
115
116 /*! Prints the info about the layer. */
117 void Print() const;
118
119 /*! Writes the information and the weights about the layer in an XML node. */
120 virtual void AddWeightsXMLTo(void *parent);
121
122 /*! Read the information and the weights about the layer from XML node. */
123 virtual void ReadWeightsFromXML(void *parent);
124
125 /*! Getters */
126 size_t GetFilterDepth() const { return fFilterDepth; }
127 size_t GetFilterHeight() const { return fFilterHeight; }
128 size_t GetFilterWidth() const { return fFilterWidth; }
129
130 size_t GetStrideRows() const { return fStrideRows; }
131 size_t GetStrideCols() const { return fStrideCols; }
132
133 size_t GetPaddingHeight() const { return fPaddingHeight; }
134 size_t GetPaddingWidth() const { return fPaddingWidth; }
135
136 size_t GetNLocalViewPixels() const { return fNLocalViewPixels; }
137 size_t GetNLocalViews() const { return fNLocalViews; }
138
140
141 const std::vector<Matrix_t> &GetDerivatives() const { return fDerivatives; }
142 std::vector<Matrix_t> &GetDerivatives() { return fDerivatives; }
143
144 Matrix_t &GetDerivativesAt(size_t i) { return fDerivatives[i]; }
145 const Matrix_t &GetDerivativesAt(size_t i) const { return fDerivatives[i]; }
146
147 const std::vector<Matrix_t> &GetForwardMatrices() const { return fForwardMatrices; }
148 std::vector<Matrix_t> &GetForwardMatrices() { return fForwardMatrices; }
149
153};
154
155typedef struct TConvParams {
156
157public:
158 size_t batchSize; ///< Batch size used for training and evaluation
159
160 size_t inputDepth; ///< The depth of the previous layer or input.
161 size_t inputHeight; ///< The height of the previous layer or input.
162 size_t inputWidth; ///< The width of the previous layer or input.
163
164 size_t numberFilters; ///< The number of the filters, which is equal to the output's depth.
165 size_t filterHeight; ///< The height of the filter.
166 size_t filterWidth; ///< The width of the filter.
167
168 size_t strideRows; ///< The number of row pixels to slid the filter each step.
169 size_t strideCols; ///< The number of column pixels to slid the filter each step.
170 size_t paddingHeight; ///< The number of zero layers added top and bottom of the input.
171 size_t paddingWidth; ///< The number of zero layers left and right of the input.
172
173 TConvParams(size_t _batchSize, size_t _inputDepth, size_t _inputHeight, size_t _inputWidth, size_t _numberFilters,
174 size_t _filterHeight, size_t _filterWidth, size_t _strideRows, size_t _strideCols,
175 size_t _paddingHeight, size_t _paddingWidth)
176 : batchSize(_batchSize), inputDepth(_inputDepth), inputHeight(_inputHeight), inputWidth(_inputWidth),
177 numberFilters(_numberFilters), filterHeight(_filterHeight), filterWidth(_filterWidth),
178 strideRows(_strideRows), strideCols(_strideCols), paddingHeight(_paddingHeight),
179 paddingWidth(_paddingWidth)
180 {}
182
183
184//
185//
186// Conv Layer Class - Implementation
187//______________________________________________________________________________
188template <typename Architecture_t>
189TConvLayer<Architecture_t>::TConvLayer(size_t batchSize, size_t inputDepth, size_t inputHeight, size_t inputWidth,
190 size_t depth, EInitialization init, size_t filterHeight, size_t filterWidth,
191 size_t strideRows, size_t strideCols, size_t paddingHeight, size_t paddingWidth,
192 Scalar_t dropoutProbability, EActivationFunction f, ERegularization reg,
194 : VGeneralLayer<Architecture_t>(batchSize, inputDepth, inputHeight, inputWidth, depth,
195 calculateDimension(inputHeight, filterHeight, paddingHeight, strideRows),
196 calculateDimension(inputWidth, filterWidth, paddingWidth, strideCols),
197 1, depth, calculateNLocalViewPixels(inputDepth, filterHeight, filterWidth),
198 1, depth, 1, batchSize, depth,
199 calculateNLocalViews(inputHeight, filterHeight, paddingHeight, strideRows,
200 inputWidth, filterWidth, paddingWidth, strideCols),
201 init),
202 fFilterDepth(inputDepth), fFilterHeight(filterHeight), fFilterWidth(filterWidth), fStrideRows(strideRows),
203 fStrideCols(strideCols), fNLocalViewPixels(calculateNLocalViewPixels(inputDepth, filterHeight, filterWidth)),
204 fNLocalViews(calculateNLocalViews(inputHeight, filterHeight, paddingHeight, strideRows,
205 inputWidth, filterWidth, paddingWidth, strideCols)),
206 fDropoutProbability(dropoutProbability), fPaddingHeight(paddingHeight), fPaddingWidth(paddingWidth),
207 fDerivatives(), fF(f), fReg(reg), fWeightDecay(weightDecay)
208{
209 /** Each element in the vector is a `T_Matrix` representing an event, therefore `vec.size() == batchSize`.
210 * Cells in these matrices are distributed in the following manner:
211 * Each row represents a single feature map, therefore we have `nRows == depth`.
212 * Each column represents a single pixel in that feature map, therefore we have `nCols == nLocalViews`.
213 **/
214 for (size_t i = 0; i < batchSize; i++) {
215 fDerivatives.emplace_back(depth, fNLocalViews);
217 }
218 Architecture_t::PrepareInternals(fForwardMatrices);
219}
220
221//______________________________________________________________________________
222template <typename Architecture_t>
224 : VGeneralLayer<Architecture_t>(layer), fFilterDepth(layer->GetFilterDepth()),
225 fFilterHeight(layer->GetFilterHeight()), fFilterWidth(layer->GetFilterWidth()),
226 fStrideRows(layer->GetStrideRows()), fStrideCols(layer->GetStrideCols()),
227 fNLocalViewPixels(layer->GetNLocalViewPixels()), fNLocalViews(layer->GetNLocalViews()),
228 fDropoutProbability(layer->GetDropoutProbability()), fPaddingHeight(layer->GetPaddingHeight()),
229 fPaddingWidth(layer->GetPaddingWidth()), fF(layer->GetActivationFunction()),
230 fReg(layer->GetRegularization()), fWeightDecay(layer->GetWeightDecay())
231{
232 size_t outputNSlices = (layer->GetDerivatives()).size();
233 size_t outputNRows = 0;
234 size_t outputNCols = 0;
235
236 for (size_t i = 0; i < outputNSlices; i++) {
237 outputNRows = (layer->GetDerivativesAt(i)).GetNrows();
238 outputNCols = (layer->GetDerivativesAt(i)).GetNcols();
239 fDerivatives.emplace_back(outputNRows, outputNCols);
240 fForwardMatrices.emplace_back(layer->GetNLocalViews(), layer->GetNLocalViewPixels());
241 }
242}
243
244//______________________________________________________________________________
245template <typename Architecture_t>
247 : VGeneralLayer<Architecture_t>(convLayer), fFilterDepth(convLayer.fFilterDepth),
248 fFilterHeight(convLayer.fFilterHeight), fFilterWidth(convLayer.fFilterWidth), fStrideRows(convLayer.fStrideRows),
249 fStrideCols(convLayer.fStrideCols), fNLocalViewPixels(convLayer.fNLocalViewPixels),
250 fNLocalViews(convLayer.fNLocalViews), fDropoutProbability(convLayer.fDropoutProbability),
251 fPaddingHeight(convLayer.fPaddingHeight), fPaddingWidth(convLayer.fPaddingWidth), fF(convLayer.fF),
252 fReg(convLayer.fReg), fWeightDecay(convLayer.fWeightDecay)
253{
254 size_t outputNSlices = convLayer.fDerivatives.size();
255 size_t outputNRows = convLayer.GetDerivativesAt(0).GetNrows();
256 size_t outputNCols = convLayer.GetDerivativesAt(0).GetNcols();
257
258 for (size_t i = 0; i < outputNSlices; i++) {
259 fDerivatives.emplace_back(outputNRows, outputNCols);
260 fForwardMatrices.emplace_back(convLayer.fNLocalViews, convLayer.fNLocalViewPixels);
261 }
262}
263
264//______________________________________________________________________________
265template <typename Architecture_t>
267{
268}
269
270//______________________________________________________________________________
271template <typename Architecture_t>
272auto TConvLayer<Architecture_t>::Forward(std::vector<Matrix_t> &input, bool /*applyDropout*/) -> void
273{
274 TConvParams params(this->GetBatchSize(), this->GetInputDepth(), this->GetInputHeight(), this->GetInputWidth(),
275 this->GetDepth(), this->GetFilterHeight(), this->GetFilterWidth(),
276 this->GetStrideRows(), this->GetStrideCols(), this->GetPaddingHeight(), this->GetPaddingWidth());
277
278 R__ASSERT( input.size() > 0);
279 Architecture_t::ConvLayerForward(this->GetOutput(), this->GetDerivatives(), input, this->GetWeightsAt(0),
280 this->GetBiasesAt(0), params, this->GetActivationFunction(),
281 this->GetForwardMatrices());
282
283#if 0
284 // in printciple I could make the indices data member of the class
285 Matrix_t inputTr(this->GetNLocalViews(), this->GetNLocalViewPixels());
286 //Matrix_t inputTr2(this->GetNLocalViews(), this->GetNLocalViewPixels());
287 std::vector<int> vIndices(inputTr.GetNrows() * inputTr.GetNcols() );
288 R__ASSERT( input.size() > 0);
289 Architecture_t::Im2colIndices(vIndices, input[0], this->GetNLocalViews(), this->GetInputHeight(), this->GetInputWidth(), this->GetFilterHeight(),
290 this->GetFilterWidth(), this->GetStrideRows(), this->GetStrideCols(),
291 this->GetPaddingHeight(), this->GetPaddingWidth());
292 // batch size loop
293 for (size_t i = 0; i < this->GetBatchSize(); i++) {
294
295 if (applyDropout && (this->GetDropoutProbability() != 1.0)) {
296 Architecture_t::Dropout(input[i], this->GetDropoutProbability());
297 }
298
299 inputTr.Zero();
300 //inputTr2.Zero();
301 // Architecture_t::Im2col(inputTr2, input[i], this->GetInputHeight(), this->GetInputWidth(), this->GetFilterHeight(),
302 // this->GetFilterWidth(), this->GetStrideRows(), this->GetStrideCols(),
303 // this->GetPaddingHeight(), this->GetPaddingWidth());
304 Architecture_t::Im2colFast(inputTr, input[i], vIndices);
305 // bool diff = false;
306 // for (int j = 0; j < inputTr.GetNrows(); ++j) {
307 // for (int k = 0; k < inputTr.GetNcols(); ++k) {
308 // if ( inputTr2(j,k) != inputTr(j,k) ) {
309 // diff = true;
310 // std::cout << "different im2col for " << j << " , " << k << " " << inputTr(j,k) << " shoud be " << inputTr2(j,k) << std::endl;
311 // }
312 // }
313 // }
314 // if (diff) {
315 // std::cout << "ConvLayer:: Different Im2Col for batch " << i << std::endl;
316 // printf("Layer parameters : %d x %d , filter %d x %d , stride %d %d , pad %d %d \n",this->GetInputHeight(), this->GetInputWidth(), this->GetFilterHeight(),
317 // this->GetFilterWidth(), this->GetStrideRows(), this->GetStrideCols(),
318 // this->GetPaddingHeight(), this->GetPaddingWidth() );
319 // // TMVA_DNN_PrintTCpuMatrix(inputTr);
320 // // TMVA_DNN_PrintTCpuMatrix(inputTr2);
321 // }
322 // R__ASSERT(!diff);
323 Architecture_t::MultiplyTranspose(this->GetOutputAt(i), this->GetWeightsAt(0), inputTr);
324 Architecture_t::AddConvBiases(this->GetOutputAt(i), this->GetBiasesAt(0));
325
326 evaluateDerivative<Architecture_t>(this->GetDerivativesAt(i), fF, this->GetOutputAt(i));
327 evaluate<Architecture_t>(this->GetOutputAt(i), fF);
328 }
329#endif
330}
331
332//______________________________________________________________________________
333template <typename Architecture_t>
334auto TConvLayer<Architecture_t>::Backward(std::vector<Matrix_t> &gradients_backward,
335 const std::vector<Matrix_t> &activations_backward,
336 std::vector<Matrix_t> & /*inp1*/, std::vector<Matrix_t> &
337 /*inp2*/) -> void
338{
339 Architecture_t::ConvLayerBackward(
340 gradients_backward, this->GetWeightGradientsAt(0), this->GetBiasGradientsAt(0), this->GetDerivatives(),
341 this->GetActivationGradients(), this->GetWeightsAt(0), activations_backward, this->GetBatchSize(),
342 this->GetInputHeight(), this->GetInputWidth(), this->GetDepth(), this->GetHeight(), this->GetWidth(),
343 this->GetFilterDepth(), this->GetFilterHeight(), this->GetFilterWidth(), this->GetNLocalViews());
344
345 addRegularizationGradients<Architecture_t>(this->GetWeightGradientsAt(0), this->GetWeightsAt(0),
346 this->GetWeightDecay(), this->GetRegularization());
347}
348
349//______________________________________________________________________________
350template <typename Architecture_t>
352{
353 std::cout << " CONV LAYER: \t";
354 std::cout << "( W = " << this->GetWidth() << " , ";
355 std::cout << " H = " << this->GetHeight() << " , ";
356 std::cout << " D = " << this->GetDepth() << " ) ";
357
358 std::cout << "\t Filter ( W = " << this->GetFilterWidth() << " , ";
359 std::cout << " H = " << this->GetFilterHeight() << " ) ";
360 //std::cout << "\t Local Views = " << this->GetNLocalViews() << " " ;
361 if (this->GetOutput().size() > 0) {
362 std::cout << "\tOutput = ( " << this->GetOutput().size() << " , " << this->GetOutput()[0].GetNrows() << " , " << this->GetOutput()[0].GetNcols() << " ) ";
363 }
364 std::vector<std::string> activationNames = { "Identity","Relu","Sigmoid","Tanh","SymmRelu","SoftSign","Gauss" };
365 std::cout << "\t Activation Function = ";
366 std::cout << activationNames[ static_cast<int>(fF) ] << std::endl;
367}
368
369//______________________________________________________________________________
370template <typename Architecture_t>
372{
373 auto layerxml = gTools().xmlengine().NewChild(parent, 0, "ConvLayer");
374
375 gTools().xmlengine().NewAttr(layerxml, 0, "Depth", gTools().StringFromInt(this->GetDepth()));
376 gTools().xmlengine().NewAttr(layerxml, 0, "FilterHeight", gTools().StringFromInt(this->GetFilterHeight()));
377 gTools().xmlengine().NewAttr(layerxml, 0, "FilterWidth", gTools().StringFromInt(this->GetFilterWidth()));
378 gTools().xmlengine().NewAttr(layerxml, 0, "StrideRows", gTools().StringFromInt(this->GetStrideRows()));
379 gTools().xmlengine().NewAttr(layerxml, 0, "StrideCols", gTools().StringFromInt(this->GetStrideCols()));
380 gTools().xmlengine().NewAttr(layerxml, 0, "PaddingHeight", gTools().StringFromInt(this->GetPaddingHeight()));
381 gTools().xmlengine().NewAttr(layerxml, 0, "PaddingWidth", gTools().StringFromInt(this->GetPaddingWidth()));
382
383
384 int activationFunction = static_cast<int>(this -> GetActivationFunction());
385 gTools().xmlengine().NewAttr(layerxml, 0, "ActivationFunction",
386 TString::Itoa(activationFunction, 10));
387
388 // write weights and bias matrix
389 this->WriteMatrixToXML(layerxml, "Weights", this -> GetWeightsAt(0));
390 this->WriteMatrixToXML(layerxml, "Biases", this -> GetBiasesAt(0));
391
392}
393
394//______________________________________________________________________________
395template <typename Architecture_t>
397{
398 // read weights and biases
399 // the meta information is read before because it is needed before creating the Conv layer
400 this->ReadMatrixXML(parent,"Weights", this -> GetWeightsAt(0));
401 this->ReadMatrixXML(parent,"Biases", this -> GetBiasesAt(0));
402}
403
404template <typename Architecture_t>
405size_t TConvLayer<Architecture_t>::calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride)
406{
407 size_t temp = imgDim - fltDim + 2 * padding;
408 if (temp % stride || temp + stride <= 0) {
409 Fatal("calculateDimension", "Not compatible hyper parameters for layer - (imageDim, filterDim, padding, stride) "
410 "%zu, %zu, %zu, %zu", imgDim, fltDim, padding, stride);
411 }
412 return temp / stride + 1;
413}
414
415template <typename Architecture_t>
416size_t TConvLayer<Architecture_t>::calculateNLocalViews(size_t inputHeight, size_t filterHeight, size_t paddingHeight,
417 size_t strideRows, size_t inputWidth, size_t filterWidth,
418 size_t paddingWidth, size_t strideCols)
419{
420 int height = calculateDimension(inputHeight, filterHeight, paddingHeight, strideRows);
421 int width = calculateDimension(inputWidth, filterWidth, paddingWidth, strideCols);
422
423 return height * width;
424}
425
426} // namespace CNN
427} // namespace DNN
428} // namespace TMVA
429
430#endif
#define f(i)
Definition: RSha256.hxx:104
static Int_t init()
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
#define R__ASSERT(e)
Definition: TError.h:96
void Fatal(const char *location, const char *msgfmt,...)
size_t fNLocalViews
The number of local views in one image.
Definition: ConvLayer.h:68
void Forward(std::vector< Matrix_t > &input, bool applyDropout=false)
Computes activation of the layer for the given input.
Definition: ConvLayer.h:272
size_t calculateNLocalViews(size_t inputHeight, size_t filterHeight, size_t paddingHeight, size_t strideRows, size_t inputWidth, size_t filterWidth, size_t paddingWidth, size_t strideCols)
Definition: ConvLayer.h:416
virtual void ReadWeightsFromXML(void *parent)
Read the information and the weights about the layer from XML node.
Definition: ConvLayer.h:396
size_t GetNLocalViewPixels() const
Definition: ConvLayer.h:136
const std::vector< Matrix_t > & GetDerivatives() const
Definition: ConvLayer.h:141
void Backward(std::vector< Matrix_t > &gradients_backward, const std::vector< Matrix_t > &activations_backward, std::vector< Matrix_t > &inp1, std::vector< Matrix_t > &inp2)
Compute weight, bias and activation gradients.
Definition: ConvLayer.h:334
size_t GetStrideRows() const
Definition: ConvLayer.h:130
std::vector< Matrix_t > fDerivatives
First fDerivatives of the activations of this layer.
Definition: ConvLayer.h:76
size_t fPaddingWidth
The number of zero layers left and right of the input.
Definition: ConvLayer.h:74
Scalar_t GetWeightDecay() const
Definition: ConvLayer.h:152
Scalar_t fWeightDecay
The weight decay.
Definition: ConvLayer.h:82
size_t fFilterWidth
The width of the filter.
Definition: ConvLayer.h:62
std::vector< int > fBackwardIndices
Vector of indices used for a fast Im2Col in backward pass.
Definition: ConvLayer.h:78
size_t calculateNLocalViewPixels(size_t depth, size_t height, size_t width)
Definition: ConvLayer.h:53
size_t GetFilterWidth() const
Definition: ConvLayer.h:128
TConvLayer(size_t BatchSize, size_t InputDepth, size_t InputHeight, size_t InputWidth, size_t Depth, EInitialization Init, size_t FilterHeight, size_t FilterWidth, size_t StrideRows, size_t StrideCols, size_t PaddingHeight, size_t PaddingWidth, Scalar_t DropoutProbability, EActivationFunction f, ERegularization Reg, Scalar_t WeightDecay)
Constructor.
Definition: ConvLayer.h:189
size_t calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride)
Definition: ConvLayer.h:405
std::vector< Matrix_t > fForwardMatrices
Vector of matrices used for speeding-up the forward pass.
Definition: ConvLayer.h:84
size_t fFilterDepth
The depth of the filter.
Definition: ConvLayer.h:60
size_t GetPaddingWidth() const
Definition: ConvLayer.h:134
size_t fNLocalViewPixels
The number of pixels in one local image view.
Definition: ConvLayer.h:67
const Matrix_t & GetDerivativesAt(size_t i) const
Definition: ConvLayer.h:145
Scalar_t fDropoutProbability
Probability that an input is active.
Definition: ConvLayer.h:70
size_t fStrideCols
The number of column pixels to slid the filter each step.
Definition: ConvLayer.h:65
~TConvLayer()
Destructor.
Definition: ConvLayer.h:266
const std::vector< Matrix_t > & GetForwardMatrices() const
Definition: ConvLayer.h:147
size_t fStrideRows
The number of row pixels to slid the filter each step.
Definition: ConvLayer.h:64
ERegularization fReg
The regularization method.
Definition: ConvLayer.h:81
typename Architecture_t::Matrix_t Matrix_t
Definition: ConvLayer.h:45
EActivationFunction GetActivationFunction() const
Definition: ConvLayer.h:150
std::vector< Matrix_t > & GetForwardMatrices()
Definition: ConvLayer.h:148
size_t fPaddingHeight
The number of zero layers added top and bottom of the input.
Definition: ConvLayer.h:73
size_t fFilterHeight
The height of the filter.
Definition: ConvLayer.h:61
size_t GetStrideCols() const
Definition: ConvLayer.h:131
virtual void AddWeightsXMLTo(void *parent)
Writes the information and the weights about the layer in an XML node.
Definition: ConvLayer.h:371
EActivationFunction fF
Activation function of the layer.
Definition: ConvLayer.h:80
size_t GetFilterDepth() const
Getters.
Definition: ConvLayer.h:126
size_t GetPaddingHeight() const
Definition: ConvLayer.h:133
size_t GetFilterHeight() const
Definition: ConvLayer.h:127
size_t GetNLocalViews() const
Definition: ConvLayer.h:137
Matrix_t & GetDerivativesAt(size_t i)
Definition: ConvLayer.h:144
Scalar_t GetDropoutProbability() const
Definition: ConvLayer.h:139
typename Architecture_t::Scalar_t Scalar_t
Definition: ConvLayer.h:46
void Print() const
Prints the info about the layer.
Definition: ConvLayer.h:351
ERegularization GetRegularization() const
Definition: ConvLayer.h:151
std::vector< Matrix_t > & GetDerivatives()
Definition: ConvLayer.h:142
Generic General Layer class.
Definition: GeneralLayer.h:46
TXMLEngine & xmlengine()
Definition: Tools.h:270
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
Definition: TString.cxx:2025
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
Definition: TXMLEngine.cxx:580
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
Definition: TXMLEngine.cxx:709
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:144
struct TMVA::DNN::CNN::TConvParams TConvParams
EInitialization
Definition: Functions.h:70
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
Definition: NeuralNet.icc:496
ERegularization
Enum representing the regularization type applied for a given layer.
Definition: Functions.h:63
EActivationFunction
Enum that represents layer activation functions.
Definition: Functions.h:32
UInt_t Depth(const Node< T > *node)
Definition: NodekNN.h:213
create variable transformations
Tools & gTools()
size_t strideRows
The number of row pixels to slid the filter each step.
Definition: ConvLayer.h:168
size_t filterHeight
The height of the filter.
Definition: ConvLayer.h:165
size_t inputHeight
The height of the previous layer or input.
Definition: ConvLayer.h:161
size_t batchSize
Batch size used for training and evaluation.
Definition: ConvLayer.h:158
size_t paddingWidth
The number of zero layers left and right of the input.
Definition: ConvLayer.h:171
size_t filterWidth
The width of the filter.
Definition: ConvLayer.h:166
size_t paddingHeight
The number of zero layers added top and bottom of the input.
Definition: ConvLayer.h:170
size_t inputWidth
The width of the previous layer or input.
Definition: ConvLayer.h:162
TConvParams(size_t _batchSize, size_t _inputDepth, size_t _inputHeight, size_t _inputWidth, size_t _numberFilters, size_t _filterHeight, size_t _filterWidth, size_t _strideRows, size_t _strideCols, size_t _paddingHeight, size_t _paddingWidth)
Definition: ConvLayer.h:173
size_t numberFilters
The number of the filters, which is equal to the output's depth.
Definition: ConvLayer.h:164
size_t inputDepth
The depth of the previous layer or input.
Definition: ConvLayer.h:160
size_t strideCols
The number of column pixels to slid the filter each step.
Definition: ConvLayer.h:169