tesseract  5.0.0
maxpool.h
Go to the documentation of this file.
1 // File: maxpool.h
3 // Description: Standard Max-Pooling layer.
4 // Author: Ray Smith
5 // Created: Tue Mar 18 16:28:18 PST 2014
6 //
7 // (C) Copyright 2014, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
18 
19 #ifndef TESSERACT_LSTM_MAXPOOL_H_
20 #define TESSERACT_LSTM_MAXPOOL_H_
21 
22 #include "reconfig.h"
23 
24 namespace tesseract {
25 
26 // Maxpooling reduction. Independently for each input, selects the location
27 // in the rectangle that contains the max value.
28 // Backprop propagates only to the position that was the max.
29 class Maxpool : public Reconfig {
30 public:
31  TESS_API
32  Maxpool(const char *name, int ni, int x_scale, int y_scale);
33  ~Maxpool() override = default;
34 
35  // Accessors.
36  std::string spec() const override {
37  return "Mp" + std::to_string(y_scale_) + "," + std::to_string(x_scale_);
38  }
39 
40  // Reads from the given file. Returns false in case of error.
41  bool DeSerialize(TFile *fp) override;
42 
43  // Runs forward propagation of activations on the input line.
44  // See Network for a detailed discussion of the arguments.
45  void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose,
46  NetworkScratch *scratch, NetworkIO *output) override;
47 
48  // Runs backward propagation of errors on the deltas line.
49  // See Network for a detailed discussion of the arguments.
50  bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch,
51  NetworkIO *back_deltas) override;
52 
53 private:
54  // Memory of which input was the max.
55  GENERIC_2D_ARRAY<int> maxes_;
56 };
57 
58 } // namespace tesseract.
59 
60 #endif // TESSERACT_LSTM_MAXPOOL_H_
std::string spec() const override
Definition: maxpool.h:36
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: maxpool.cpp:70
~Maxpool() override=default
bool DeSerialize(TFile *fp) override
Definition: maxpool.cpp:29
TESS_API Maxpool(const char *name, int ni, int x_scale, int y_scale)
Definition: maxpool.cpp:22
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: maxpool.cpp:37
const std::string & name() const
Definition: network.h:140
int32_t y_scale_
Definition: reconfig.h:78
int32_t x_scale_
Definition: reconfig.h:77
#define TESS_API
Definition: export.h:34