Logo ROOT  
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 
32 #include "TMVA/DNN/GeneralLayer.h"
33 #include "TMVA/DNN/Functions.h"
35 
36 #include <vector>
37 #include <iostream>
38 #include <string>
39 
40 namespace TMVA {
41 namespace DNN {
42 namespace CNN {
43 
44 typedef struct TConvParams {
45 
46 public:
47  size_t batchSize; ///< Batch size used for training and evaluation
48 
49  size_t inputDepth; ///< The depth of the previous layer or input.
50  size_t inputHeight; ///< The height of the previous layer or input.
51  size_t inputWidth; ///< The width of the previous layer or input.
52 
53  size_t numberFilters; ///< The number of the filters, which is equal to the output's depth.
54  size_t filterHeight; ///< The height of the filter.
55  size_t filterWidth; ///< The width of the filter.
56 
57  size_t strideRows; ///< The number of row pixels to slid the filter each step.
58  size_t strideCols; ///< The number of column pixels to slid the filter each step.
59  size_t paddingHeight; ///< The number of zero layers added top and bottom of the input.
60  size_t paddingWidth; ///< The number of zero layers left and right of the input.
61 
62  TConvParams(size_t _batchSize, size_t _inputDepth, size_t _inputHeight, size_t _inputWidth, size_t _numberFilters,
63  size_t _filterHeight, size_t _filterWidth, size_t _strideRows, size_t _strideCols,
64  size_t _paddingHeight, size_t _paddingWidth)
65  : batchSize(_batchSize), inputDepth(_inputDepth), inputHeight(_inputHeight), inputWidth(_inputWidth),
66  numberFilters(_numberFilters), filterHeight(_filterHeight), filterWidth(_filterWidth),
67  strideRows(_strideRows), strideCols(_strideCols), paddingHeight(_paddingHeight),
68  paddingWidth(_paddingWidth)
69  {}
71 
72 
73 
74 template <typename Architecture_t>
75 class TConvLayer : public VGeneralLayer<Architecture_t> {
76 public:
77  using Tensor_t = typename Architecture_t::Tensor_t;
78  using Matrix_t = typename Architecture_t::Matrix_t;
79  using Scalar_t = typename Architecture_t::Scalar_t;
80 
81  using LayerDescriptor_t = typename Architecture_t::ConvolutionDescriptor_t;
82  using WeightsDescriptor_t = typename Architecture_t::FilterDescriptor_t;
83  using HelperDescriptor_t = typename Architecture_t::ActivationDescriptor_t;
84 
85  using AlgorithmForward_t = typename Architecture_t::AlgorithmForward_t; // Forward layer operation
86  using AlgorithmBackward_t = typename Architecture_t::AlgorithmBackward_t; // Backward layer operation
87  using AlgorithmHelper_t = typename Architecture_t::AlgorithmHelper_t; // Used for weight grad backward pass
88  using ReduceTensorDescriptor_t = typename Architecture_t::ReduceTensorDescriptor_t; // used for reduction of tensor(bias grad)
89 
90  // FIXME: Add other cudnn types (algorithm preference etc.)
91  using AlgorithmDataType_t = typename Architecture_t::AlgorithmDataType_t;
92 
93  /* Calculate the output dimension of the convolutional layer */
94  static size_t calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride);
95 
96  /* Calculate the number of pixels in a single receptive field */
97  static size_t inline calculateNLocalViewPixels(size_t depth, size_t height, size_t width) { return depth * height * width; }
98 
99  /* Calculate the number of receptive fields in an image given the filter and image sizes */
100  static size_t calculateNLocalViews(size_t inputHeight, size_t filterHeight, size_t paddingHeight, size_t strideRows,
101  size_t inputWidth, size_t filterWidth, size_t paddingWidth, size_t strideCols);
102 
103 protected:
104  size_t fFilterDepth; ///< The depth of the filter.
105  size_t fFilterHeight; ///< The height of the filter.
106  size_t fFilterWidth; ///< The width of the filter.
107 
108  size_t fStrideRows; ///< The number of row pixels to slid the filter each step.
109  size_t fStrideCols; ///< The number of column pixels to slid the filter each step.
110 
111  size_t fNLocalViewPixels; ///< The number of pixels in one local image view.
112  size_t fNLocalViews; ///< The number of local views in one image.
113 
114  Scalar_t fDropoutProbability; ///< Probability that an input is active.
115 
116  TDescriptors * fDescriptors = nullptr; ///< Keeps the convolution, activations and filter descriptors
117 
118  TWorkspace * fWorkspace = nullptr;
119 private:
120  size_t fPaddingHeight; ///< The number of zero layers added top and bottom of the input.
121  size_t fPaddingWidth; ///< The number of zero layers left and right of the input.
122 
123  Tensor_t fInputActivation; ///< First output of this layer after conv, before activation.
124 
125  std::vector<int> fBackwardIndices; ///< Vector of indices used for a fast Im2Col in backward pass
126 
127  EActivationFunction fF; ///< Activation function of the layer.
128  ERegularization fReg; ///< The regularization method.
129  Scalar_t fWeightDecay; ///< The weight decay.
130 
131  Tensor_t fForwardTensor; ///< Cache tensor used for speeding-up the forward pass.
132 
133  void InitializeDescriptors();
134  void ReleaseDescriptors();
135  void InitializeWorkspace();
136  void FreeWorkspace();
137 
138 public:
139  /*! Constructor. */
140  TConvLayer(size_t BatchSize, size_t InputDepth, size_t InputHeight, size_t InputWidth, size_t Depth, EInitialization Init,
141  size_t FilterHeight, size_t FilterWidth, size_t StrideRows, size_t StrideCols, size_t PaddingHeight,
142  size_t PaddingWidth, Scalar_t DropoutProbability, EActivationFunction f, ERegularization Reg,
143  Scalar_t WeightDecay);
144 
145  /*! Copy the conv layer provided as a pointer */
147 
148  /*! Copy constructor. */
149  TConvLayer(const TConvLayer &);
150 
151  /*! Destructor. */
152  virtual ~TConvLayer();
153 
154  //virtual void Initialize();
155 
156  /*! Computes activation of the layer for the given input. The input
157  * must be in 3D tensor form with the different matrices corresponding to
158  * different events in the batch. Computes activations as well as
159  * the first partial derivative of the activation function at those
160  * activations. */
161  void Forward(Tensor_t &input, bool applyDropout = false);
162 
163  /*! Compute weight, bias and activation gradients. Uses the precomputed
164  * first partial derviatives of the activation function computed during
165  * forward propagation and modifies them. Must only be called directly
166  * at the corresponding call to Forward(...). */
167  void Backward(Tensor_t &gradients_backward, const Tensor_t &activations_backward);
168  //// Tensor_t &inp1, Tensor_t &inp2);
169 
170  /*! Prints the info about the layer. */
171  void Print() const;
172 
173  /*! Writes the information and the weights about the layer in an XML node. */
174  virtual void AddWeightsXMLTo(void *parent);
175 
176  /*! Read the information and the weights about the layer from XML node. */
177  virtual void ReadWeightsFromXML(void *parent);
178 
179  /*! Getters */
180  size_t GetFilterDepth() const { return fFilterDepth; }
181  size_t GetFilterHeight() const { return fFilterHeight; }
182  size_t GetFilterWidth() const { return fFilterWidth; }
183 
184  size_t GetStrideRows() const { return fStrideRows; }
185  size_t GetStrideCols() const { return fStrideCols; }
186 
187  size_t GetPaddingHeight() const { return fPaddingHeight; }
188  size_t GetPaddingWidth() const { return fPaddingWidth; }
189 
190  size_t GetNLocalViewPixels() const { return fNLocalViewPixels; }
191  size_t GetNLocalViews() const { return fNLocalViews; }
192 
194 
195  const Tensor_t &GetInputActivation() const { return fInputActivation; }
197 
199  const Matrix_t &GetInputActivationAt(size_t i) const { return fInputActivation[i]; }
200 
201  const Tensor_t &GetForwardMatrices() const { return fForwardTensor; }
203 
207 
208  // The following getters are used for testing
210  const TDescriptors * GetDescriptors() const {return fDescriptors;}
211 
213  const TWorkspace * GetWorkspace() const {return fWorkspace;}
214 };
215 
216 
217 //
218 //
219 // Conv Layer Class - Implementation
220 //______________________________________________________________________________
221 template <typename Architecture_t>
222 TConvLayer<Architecture_t>::TConvLayer(size_t batchSize, size_t inputDepth, size_t inputHeight, size_t inputWidth,
223  size_t depth, EInitialization init, size_t filterHeight, size_t filterWidth,
224  size_t strideRows, size_t strideCols, size_t paddingHeight, size_t paddingWidth,
225  Scalar_t dropoutProbability, EActivationFunction f, ERegularization reg,
227  : VGeneralLayer<Architecture_t>(batchSize, inputDepth, inputHeight, inputWidth, depth,
228  calculateDimension(inputHeight, filterHeight, paddingHeight, strideRows),
229  calculateDimension(inputWidth, filterWidth, paddingWidth, strideCols),
230  1, depth, calculateNLocalViewPixels(inputDepth, filterHeight, filterWidth),
231  1, depth, 1, batchSize, depth,
232  calculateNLocalViews(inputHeight, filterHeight, paddingHeight, strideRows,
233  inputWidth, filterWidth, paddingWidth, strideCols),
234  init),
235  fFilterDepth(inputDepth), fFilterHeight(filterHeight), fFilterWidth(filterWidth), fStrideRows(strideRows),
236  fStrideCols(strideCols), fNLocalViewPixels(calculateNLocalViewPixels(inputDepth, filterHeight, filterWidth)),
237  fNLocalViews(calculateNLocalViews(inputHeight, filterHeight, paddingHeight, strideRows,
238  inputWidth, filterWidth, paddingWidth, strideCols)),
239  fDropoutProbability(dropoutProbability), fPaddingHeight(paddingHeight), fPaddingWidth(paddingWidth),
240  fInputActivation(), fF(f), fReg(reg), fWeightDecay(weightDecay)
241 {
242  /** Each element in the vector is a `T_Matrix` representing an event, therefore `vec.size() == batchSize`.
243  * Cells in these matrices are distributed in the following manner:
244  * Each row represents a single feature map, therefore we have `nRows == depth`.
245  * Each column represents a single pixel in that feature map, therefore we have `nCols == nLocalViews`.
246  **/
247  fInputActivation = Tensor_t( batchSize, depth, fNLocalViews); // create tensor (shape is B x C x LV)
249 
250 
253 }
254 
255 //______________________________________________________________________________
256 template <typename Architecture_t>
258  : VGeneralLayer<Architecture_t>(layer), fFilterDepth(layer->GetFilterDepth()),
259  fFilterHeight(layer->GetFilterHeight()), fFilterWidth(layer->GetFilterWidth()),
260  fStrideRows(layer->GetStrideRows()), fStrideCols(layer->GetStrideCols()),
261  fNLocalViewPixels(layer->GetNLocalViewPixels()), fNLocalViews(layer->GetNLocalViews()),
262  fDropoutProbability(layer->GetDropoutProbability()), fPaddingHeight(layer->GetPaddingHeight()),
263  fPaddingWidth(layer->GetPaddingWidth()),
264  fInputActivation( layer->GetInputActivation().GetShape() ),
265  fF(layer->GetActivationFunction()),
266  fReg(layer->GetRegularization()), fWeightDecay(layer->GetWeightDecay()),
267  fForwardTensor( layer->GetForwardMatrices().GetShape() )
268 {
271 
272 }
273 
274 //______________________________________________________________________________
275 template <typename Architecture_t>
277  : VGeneralLayer<Architecture_t>(convLayer), fFilterDepth(convLayer.fFilterDepth),
278  fFilterHeight(convLayer.fFilterHeight), fFilterWidth(convLayer.fFilterWidth), fStrideRows(convLayer.fStrideRows),
279  fStrideCols(convLayer.fStrideCols), fNLocalViewPixels(convLayer.fNLocalViewPixels),
280  fNLocalViews(convLayer.fNLocalViews), fDropoutProbability(convLayer.fDropoutProbability),
281  fPaddingHeight(convLayer.fPaddingHeight), fPaddingWidth(convLayer.fPaddingWidth),
282  fInputActivation( convLayer.GetInputActivation().GetShape() ),
283  fF(convLayer.fF),
284  fReg(convLayer.fReg), fWeightDecay(convLayer.fWeightDecay),
285  fForwardTensor( convLayer.GetForwardMatrices().GetShape() )
286 {
289 }
290 
291 //______________________________________________________________________________
292 //FIXME: Add function for cudaFree
293 template <typename Architecture_t>
295 {
296  //std::cout << "!!!!Delete conv layer " << this->GetOutput().GetShape()[1] << " " << this->GetOutput().GetShape()[2] << " " << this->GetOutput().GetShape()[3] << std::endl;
297  if (fDescriptors) {
298  ReleaseDescriptors();
299  delete fDescriptors;
300  }
301 
302  if (fWorkspace) {
303  FreeWorkspace();
304  delete fWorkspace;
305  }
306 }
307 
308 
309 //______________________________________________________________________________
310 template <typename Architecture_t>
311 auto TConvLayer<Architecture_t>::Forward(Tensor_t &input, bool /*applyDropout*/) -> void
312 {
313  TConvParams params(this->GetBatchSize(), this->GetInputDepth(), this->GetInputHeight(), this->GetInputWidth(),
314  this->GetDepth(), this->GetFilterHeight(), this->GetFilterWidth(),
315  this->GetStrideRows(), this->GetStrideCols(), this->GetPaddingHeight(), this->GetPaddingWidth());
316 
317  //R__ASSERT( input.size() > 0);
318  Architecture_t::ConvLayerForward(this->GetOutput(), this->GetInputActivation(), input, this->GetWeightsAt(0),
319  this->GetBiasesAt(0), params, this->GetActivationFunction(),
320  this->GetForwardMatrices(), (TCNNDescriptors<TConvLayer<Architecture_t>> &) (*fDescriptors),
321  (TCNNWorkspace<TConvLayer<Architecture_t>> &) (*fWorkspace));
322 }
323 
324 //______________________________________________________________________________
325 template <typename Architecture_t>
327  const Tensor_t &activations_backward) -> void
328 // Tensor_t & /*inp1*/, Tensor_t &
329 // /*inp2*/) -> void
330 {
331  Architecture_t::ConvLayerBackward(
332  gradients_backward, this->GetWeightGradientsAt(0), this->GetBiasGradientsAt(0), this->GetInputActivation(),
333  this->GetActivationGradients(), this->GetWeightsAt(0), activations_backward, this->GetOutput(),
334  this->GetActivationFunction(),
335  (TCNNDescriptors<TConvLayer<Architecture_t>> &) (*fDescriptors),
336  (TCNNWorkspace<TConvLayer<Architecture_t>> &) (*fWorkspace),
337  this->GetBatchSize(), this->GetInputHeight(), this->GetInputWidth(), this->GetDepth(),
338  this->GetHeight(), this->GetWidth(), this->GetFilterDepth(), this->GetFilterHeight(),
339  this->GetFilterWidth(), this->GetNLocalViews());
340 
341  addRegularizationGradients<Architecture_t>(this->GetWeightGradientsAt(0), this->GetWeightsAt(0),
342  this->GetWeightDecay(), this->GetRegularization());
343 }
344 
345 //______________________________________________________________________________
346 template <typename Architecture_t>
348 {
349  std::cout << " CONV LAYER: \t";
350  std::cout << "( W = " << this->GetWidth() << " , ";
351  std::cout << " H = " << this->GetHeight() << " , ";
352  std::cout << " D = " << this->GetDepth() << " ) ";
353 
354  std::cout << "\t Filter ( W = " << this->GetFilterWidth() << " , ";
355  std::cout << " H = " << this->GetFilterHeight() << " ) ";
356  //std::cout << "\t Local Views = " << this->GetNLocalViews() << " " ;
357  if (this->GetOutput().GetSize() > 0) {
358  std::cout << "\tOutput = ( " << this->GetOutput().GetFirstSize() << " , "
359  << this->GetOutput().GetCSize() << " , " << this->GetOutput().GetHSize() << " , " << this->GetOutput().GetWSize()
360  << " ) ";
361  }
362  std::vector<std::string> activationNames = { "Identity","Relu","Sigmoid","Tanh","SymmRelu","SoftSign","Gauss" };
363  std::cout << "\t Activation Function = ";
364  std::cout << activationNames[ static_cast<int>(fF) ] << std::endl;
365 }
366 
367 //______________________________________________________________________________
368 template <typename Architecture_t>
370 {
371  auto layerxml = gTools().xmlengine().NewChild(parent, 0, "ConvLayer");
372 
373  gTools().xmlengine().NewAttr(layerxml, 0, "Depth", gTools().StringFromInt(this->GetDepth()));
374  gTools().xmlengine().NewAttr(layerxml, 0, "FilterHeight", gTools().StringFromInt(this->GetFilterHeight()));
375  gTools().xmlengine().NewAttr(layerxml, 0, "FilterWidth", gTools().StringFromInt(this->GetFilterWidth()));
376  gTools().xmlengine().NewAttr(layerxml, 0, "StrideRows", gTools().StringFromInt(this->GetStrideRows()));
377  gTools().xmlengine().NewAttr(layerxml, 0, "StrideCols", gTools().StringFromInt(this->GetStrideCols()));
378  gTools().xmlengine().NewAttr(layerxml, 0, "PaddingHeight", gTools().StringFromInt(this->GetPaddingHeight()));
379  gTools().xmlengine().NewAttr(layerxml, 0, "PaddingWidth", gTools().StringFromInt(this->GetPaddingWidth()));
380 
381 
382  int activationFunction = static_cast<int>(this -> GetActivationFunction());
383  gTools().xmlengine().NewAttr(layerxml, 0, "ActivationFunction",
384  TString::Itoa(activationFunction, 10));
385 
386  // write weights and bias matrix
387  this->WriteMatrixToXML(layerxml, "Weights", this -> GetWeightsAt(0));
388  this->WriteMatrixToXML(layerxml, "Biases", this -> GetBiasesAt(0));
389 }
390 
391 //______________________________________________________________________________
392 template <typename Architecture_t>
394 {
395  // read weights and biases
396  // the meta information is read before because it is needed before creating the Conv layer
397  this->ReadMatrixXML(parent,"Weights", this -> GetWeightsAt(0));
398  this->ReadMatrixXML(parent,"Biases", this -> GetBiasesAt(0));
399 }
400 
401 template <typename Architecture_t>
402 size_t TConvLayer<Architecture_t>::calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride)
403 {
404  size_t temp = imgDim - fltDim + 2 * padding;
405  if (temp % stride || temp + stride <= 0) {
406  Fatal("calculateDimension", "Not compatible hyper parameters for layer - (imageDim, filterDim, padding, stride) "
407  "%zu, %zu, %zu, %zu", imgDim, fltDim, padding, stride);
408  }
409  return temp / stride + 1;
410 }
411 
412 template <typename Architecture_t>
413 size_t TConvLayer<Architecture_t>::calculateNLocalViews(size_t inputHeight, size_t filterHeight, size_t paddingHeight,
414  size_t strideRows, size_t inputWidth, size_t filterWidth,
415  size_t paddingWidth, size_t strideCols)
416 {
417  int height = calculateDimension(inputHeight, filterHeight, paddingHeight, strideRows);
418  int width = calculateDimension(inputWidth, filterWidth, paddingWidth, strideCols);
419 
420  return height * width;
421 }
422 
423 //______________________________________________________________________________
424 template <typename Architecture_t>
426  Architecture_t::InitializeConvDescriptors(fDescriptors, this);
427 }
428 
429 template <typename Architecture_t>
431  Architecture_t::ReleaseConvDescriptors(fDescriptors);
432 }
433 
434 //______________________________________________________________________________
435 template <typename Architecture_t>
437  TConvParams params(this->GetBatchSize(), this->GetInputDepth(), this->GetInputHeight(), this->GetInputWidth(),
438  this->GetDepth(), this->GetFilterHeight(), this->GetFilterWidth(),
439  this->GetStrideRows(), this->GetStrideCols(), this->GetPaddingHeight(), this->GetPaddingWidth());
440 
441  Architecture_t::InitializeConvWorkspace(fWorkspace, fDescriptors, params, this);
442 }
443 
444 template <typename Architecture_t>
446  Architecture_t::FreeConvWorkspace(fWorkspace);
447 }
448 
449 //______________________________________________________________________________
450 
451 } // namespace CNN
452 } // namespace DNN
453 } // namespace TMVA
454 
455 #endif
TMVA::DNN::CNN::TConvLayer::InitializeWorkspace
void InitializeWorkspace()
Definition: ConvLayer.h:436
TXMLEngine::NewAttr
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:583
ContextHandles.h
TMVA::DNN::CNN::TCNNWorkspace
Definition: ContextHandles.h:62
TMVA::DNN::CNN::TConvLayer::GetInputActivation
const Tensor_t & GetInputActivation() const
Definition: ConvLayer.h:195
TMVA::DNN::CNN::TConvLayer::GetStrideCols
size_t GetStrideCols() const
Definition: ConvLayer.h:185
TMVA::DNN::CNN::TConvLayer::GetDescriptors
const TDescriptors * GetDescriptors() const
Definition: ConvLayer.h:210
TMVA::DNN::CNN::TConvLayer::AlgorithmBackward_t
typename Architecture_t::AlgorithmBackward_t AlgorithmBackward_t
Definition: ConvLayer.h:86
TMVA::DNN::CNN::TConvLayer::fInputActivation
Tensor_t fInputActivation
First output of this layer after conv, before activation.
Definition: ConvLayer.h:123
TMVA::DNN::CNN::TConvLayer::HelperDescriptor_t
typename Architecture_t::ActivationDescriptor_t HelperDescriptor_t
Definition: ConvLayer.h:83
f
#define f(i)
Definition: RSha256.hxx:104
TXMLEngine::NewChild
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
Definition: TXMLEngine.cxx:712
TMVA::DNN::CNN::TConvLayer::fStrideRows
size_t fStrideRows
The number of row pixels to slid the filter each step.
Definition: ConvLayer.h:108
TMVA::DNN::CNN::TConvLayer::fStrideCols
size_t fStrideCols
The number of column pixels to slid the filter each step.
Definition: ConvLayer.h:109
TMVA::DNN::ERegularization
ERegularization
Enum representing the regularization type applied for a given layer.
Definition: Functions.h:65
TMVA::DNN::CNN::TConvParams::paddingHeight
size_t paddingHeight
The number of zero layers added top and bottom of the input.
Definition: ConvLayer.h:59
TMVA::DNN::CNN::TConvLayer::InitializeDescriptors
void InitializeDescriptors()
Definition: ConvLayer.h:425
TMVA::DNN::CNN::TConvParams
Definition: ConvLayer.h:44
TMVA::DNN::CNN::TConvParams::inputDepth
size_t inputDepth
The depth of the previous layer or input.
Definition: ConvLayer.h:49
TMVA::DNN::CNN::TConvLayer::AlgorithmDataType_t
typename Architecture_t::AlgorithmDataType_t AlgorithmDataType_t
Definition: ConvLayer.h:91
TMVA::DNN::CNN::TConvLayer::GetNLocalViews
size_t GetNLocalViews() const
Definition: ConvLayer.h:191
BatchHelpers::init
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)
TMVA::DNN::CNN::TConvLayer::Print
void Print() const
Prints the info about the layer.
Definition: ConvLayer.h:347
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TMVA::DNN::CNN::TConvLayer::GetDescriptors
TDescriptors * GetDescriptors()
Definition: ConvLayer.h:209
TMVA::DNN::CNN::TConvLayer::fDropoutProbability
Scalar_t fDropoutProbability
Probability that an input is active.
Definition: ConvLayer.h:114
TMVA::DNN::CNN::TConvLayer
Definition: ConvLayer.h:75
TMVA::DNN::CNN::TConvLayer::GetActivationFunction
EActivationFunction GetActivationFunction() const
Definition: ConvLayer.h:204
TMVA::DNN::CNN::TConvLayer::fPaddingHeight
size_t fPaddingHeight
The number of zero layers added top and bottom of the input.
Definition: ConvLayer.h:120
TMVA::DNN::CNN::TConvLayer::FreeWorkspace
void FreeWorkspace()
Definition: ConvLayer.h:445
TMVA::DNN::CNN::TCNNDescriptors
Definition: ContextHandles.h:51
TMVA::DNN::weightDecay
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
Definition: NeuralNet.icc:498
TMVA::DNN::CNN::TConvParams::strideRows
size_t strideRows
The number of row pixels to slid the filter each step.
Definition: ConvLayer.h:57
TMVA::DNN::CNN::TConvLayer::GetInputActivationAt
Matrix_t & GetInputActivationAt(size_t i)
Definition: ConvLayer.h:198
TMVA::DNN::CNN::TConvParams::strideCols
size_t strideCols
The number of column pixels to slid the filter each step.
Definition: ConvLayer.h:58
TMatrix.h
TString::Itoa
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
TMVA::DNN::CNN::TConvLayer::GetInputActivationAt
const Matrix_t & GetInputActivationAt(size_t i) const
Definition: ConvLayer.h:199
TMVA::DNN::CNN::TConvLayer::GetPaddingWidth
size_t GetPaddingWidth() const
Definition: ConvLayer.h:188
TMVA::DNN::CNN::TConvLayer::Forward
void Forward(Tensor_t &input, bool applyDropout=false)
Computes activation of the layer for the given input.
Definition: ConvLayer.h:311
TMVA::Tools::xmlengine
TXMLEngine & xmlengine()
Definition: Tools.h:268
TMVA::DNN::CNN::TConvLayer::fFilterHeight
size_t fFilterHeight
The height of the filter.
Definition: ConvLayer.h:105
TMVA::DNN::CNN::TConvLayer::fPaddingWidth
size_t fPaddingWidth
The number of zero layers left and right of the input.
Definition: ConvLayer.h:121
TMVA::DNN::CNN::TConvLayer::GetFilterDepth
size_t GetFilterDepth() const
Getters.
Definition: ConvLayer.h:180
TMVA::DNN::CNN::TConvLayer::GetPaddingHeight
size_t GetPaddingHeight() const
Definition: ConvLayer.h:187
TMVA::DNN::CNN::TConvLayer::fWorkspace
TWorkspace * fWorkspace
Definition: ConvLayer.h:118
TMVA::DNN::CNN::TConvLayer::GetDropoutProbability
Scalar_t GetDropoutProbability() const
Definition: ConvLayer.h:193
TMVA::DNN::CNN::TConvLayer::GetWorkspace
TWorkspace * GetWorkspace()
Definition: ConvLayer.h:212
TMVA::DNN::VGeneralLayer
Generic General Layer class.
Definition: GeneralLayer.h:51
TMVA::DNN::CNN::TConvLayer::GetFilterHeight
size_t GetFilterHeight() const
Definition: ConvLayer.h:181
TMVA::DNN::CNN::TConvLayer::fNLocalViewPixels
size_t fNLocalViewPixels
The number of pixels in one local image view.
Definition: ConvLayer.h:111
TMVA::DNN::TWorkspace
Definition: ContextHandles.h:32
TMVA::DNN::CNN::TConvLayer::calculateNLocalViews
static 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:413
TMVA::DNN::CNN::TConvLayer::GetFilterWidth
size_t GetFilterWidth() const
Definition: ConvLayer.h:182
TMVA::DNN::CNN::TConvLayer::fFilterWidth
size_t fFilterWidth
The width of the filter.
Definition: ConvLayer.h:106
TMVA::DNN::CNN::TConvLayer::GetWorkspace
const TWorkspace * GetWorkspace() const
Definition: ConvLayer.h:213
TMVA::DNN::CNN::TConvLayer::~TConvLayer
virtual ~TConvLayer()
Destructor.
Definition: ConvLayer.h:294
TMVA::DNN::CNN::TConvParams::inputWidth
size_t inputWidth
The width of the previous layer or input.
Definition: ConvLayer.h:51
TMVA::DNN::CNN::TConvLayer::fDescriptors
TDescriptors * fDescriptors
Keeps the convolution, activations and filter descriptors.
Definition: ConvLayer.h:116
TMVA::DNN::CNN::TConvParams::numberFilters
size_t numberFilters
The number of the filters, which is equal to the output's depth.
Definition: ConvLayer.h:53
Fatal
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition: TError.cxx:245
TMVA::DNN::CNN::TConvLayer::LayerDescriptor_t
typename Architecture_t::ConvolutionDescriptor_t LayerDescriptor_t
Definition: ConvLayer.h:81
TMVA::DNN::CNN::TConvLayer::GetInputActivation
Tensor_t & GetInputActivation()
Definition: ConvLayer.h:196
TMVA::DNN::CNN::TConvLayer::fReg
ERegularization fReg
The regularization method.
Definition: ConvLayer.h:128
TMVA::DNN::CNN::TConvLayer::calculateNLocalViewPixels
static size_t calculateNLocalViewPixels(size_t depth, size_t height, size_t width)
Definition: ConvLayer.h:97
TMVA::kNN::Depth
UInt_t Depth(const Node< T > *node)
Definition: NodekNN.h:214
TMVA::DNN::CNN::TConvParams::filterHeight
size_t filterHeight
The height of the filter.
Definition: ConvLayer.h:54
GeneralLayer.h
TMVA::DNN::CNN::TConvLayer::fForwardTensor
Tensor_t fForwardTensor
Cache tensor used for speeding-up the forward pass.
Definition: ConvLayer.h:131
TMVA::DNN::CNN::TConvLayer::ReleaseDescriptors
void ReleaseDescriptors()
Definition: ConvLayer.h:430
TMVA::DNN::CNN::TConvLayer::ReadWeightsFromXML
virtual void ReadWeightsFromXML(void *parent)
Read the information and the weights about the layer from XML node.
Definition: ConvLayer.h:393
TMVA::DNN::CNN::TConvParams::filterWidth
size_t filterWidth
The width of the filter.
Definition: ConvLayer.h:55
TMVA::DNN::TDescriptors
Definition: ContextHandles.h:29
TMVA::DNN::CNN::TConvLayer::GetRegularization
ERegularization GetRegularization() const
Definition: ConvLayer.h:205
TMVA::DNN::CNN::TConvLayer::AlgorithmHelper_t
typename Architecture_t::AlgorithmHelper_t AlgorithmHelper_t
Definition: ConvLayer.h:87
TMVA::DNN::CNN::TConvParams::paddingWidth
size_t paddingWidth
The number of zero layers left and right of the input.
Definition: ConvLayer.h:60
TMVA::DNN::CNN::TConvLayer::GetForwardMatrices
Tensor_t & GetForwardMatrices()
Definition: ConvLayer.h:202
TMVA::DNN::EInitialization
EInitialization
Definition: Functions.h:72
TMVA::DNN::CNN::TConvLayer::GetWeightDecay
Scalar_t GetWeightDecay() const
Definition: ConvLayer.h:206
Functions.h
TMVA::DNN::CNN::TConvLayer::fWeightDecay
Scalar_t fWeightDecay
The weight decay.
Definition: ConvLayer.h:129
TMVA::DNN::CNN::TConvParams::TConvParams
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:62
TMVA::DNN::CNN::TConvParams
struct TMVA::DNN::CNN::TConvParams TConvParams
TMVA::DNN::CNN::TConvParams::batchSize
size_t batchSize
Batch size used for training and evaluation.
Definition: ConvLayer.h:47
TMVA::DNN::CNN::TConvLayer::fBackwardIndices
std::vector< int > fBackwardIndices
Vector of indices used for a fast Im2Col in backward pass.
Definition: ConvLayer.h:125
TMVA::DNN::CNN::TConvLayer::TConvLayer
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:222
TMVA::DNN::CNN::TConvLayer::GetForwardMatrices
const Tensor_t & GetForwardMatrices() const
Definition: ConvLayer.h:201
TMVA::DNN::CNN::TConvLayer::Backward
void Backward(Tensor_t &gradients_backward, const Tensor_t &activations_backward)
Compute weight, bias and activation gradients.
Definition: ConvLayer.h:326
TMVA::DNN::CNN::TConvLayer::fNLocalViews
size_t fNLocalViews
The number of local views in one image.
Definition: ConvLayer.h:112
TMVA::DNN::CNN::TConvLayer::AddWeightsXMLTo
virtual void AddWeightsXMLTo(void *parent)
Writes the information and the weights about the layer in an XML node.
Definition: ConvLayer.h:369
TClassEdit::Init
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:154
TMVA::DNN::CNN::TConvLayer::fF
EActivationFunction fF
Activation function of the layer.
Definition: ConvLayer.h:127
TMVA::DNN::CNN::TConvLayer::ReduceTensorDescriptor_t
typename Architecture_t::ReduceTensorDescriptor_t ReduceTensorDescriptor_t
Definition: ConvLayer.h:88
TMVA::DNN::CNN::TConvLayer::GetStrideRows
size_t GetStrideRows() const
Definition: ConvLayer.h:184
TMVA::DNN::CNN::TConvLayer::AlgorithmForward_t
typename Architecture_t::AlgorithmForward_t AlgorithmForward_t
Definition: ConvLayer.h:85
TMVA::DNN::CNN::TConvLayer::Scalar_t
typename Architecture_t::Scalar_t Scalar_t
Definition: ConvLayer.h:79
TMVA::DNN::CNN::TConvLayer::calculateDimension
static size_t calculateDimension(size_t imgDim, size_t fltDim, size_t padding, size_t stride)
Definition: ConvLayer.h:402
TMVA::DNN::CNN::TConvLayer::Tensor_t
typename Architecture_t::Tensor_t Tensor_t
Definition: ConvLayer.h:77
TMVA::DNN::CNN::TConvLayer::GetNLocalViewPixels
size_t GetNLocalViewPixels() const
Definition: ConvLayer.h:190
TMVA::gTools
Tools & gTools()
TMVA::DNN::CNN::TConvLayer::WeightsDescriptor_t
typename Architecture_t::FilterDescriptor_t WeightsDescriptor_t
Definition: ConvLayer.h:82
TMVA::DNN::CNN::TConvLayer::Matrix_t
typename Architecture_t::Matrix_t Matrix_t
Definition: ConvLayer.h:78
TMVA::DNN::CNN::TConvParams::inputHeight
size_t inputHeight
The height of the previous layer or input.
Definition: ConvLayer.h:50
TMVA::DNN::EActivationFunction
EActivationFunction
Enum that represents layer activation functions.
Definition: Functions.h:32
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
TMVA::DNN::CNN::TConvLayer::fFilterDepth
size_t fFilterDepth
The depth of the filter.
Definition: ConvLayer.h:104