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