tesseract  4.0.0-1-g2a2b
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  Maxpool(const STRING& name, int ni, int x_scale, int y_scale);
32  virtual ~Maxpool() = default;
33 
34  // Accessors.
35  STRING spec() const override {
36  STRING spec;
37  spec.add_str_int("Mp", y_scale_);
39  return spec;
40  }
41 
42  // Reads from the given file. Returns false in case of error.
43  bool DeSerialize(TFile* fp) override;
44 
45  // Runs forward propagation of activations on the input line.
46  // See Network for a detailed discussion of the arguments.
47  void Forward(bool debug, const NetworkIO& input,
48  const TransposedArray* input_transpose,
49  NetworkScratch* scratch, NetworkIO* output) override;
50 
51  // Runs backward propagation of errors on the deltas line.
52  // See Network for a detailed discussion of the arguments.
53  bool Backward(bool debug, const NetworkIO& fwd_deltas,
54  NetworkScratch* scratch,
55  NetworkIO* back_deltas) override;
56 
57  private:
58  // Memory of which input was the max.
59  GENERIC_2D_ARRAY<int> maxes_;
60 };
61 
62 
63 } // namespace tesseract.
64 
65 
66 
67 
68 
69 #endif // TESSERACT_LSTM_MAXPOOL_H_
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: maxpool.cpp:39
Maxpool(const STRING &name, int ni, int x_scale, int y_scale)
Definition: maxpool.cpp:24
STRING spec() const override
Definition: maxpool.h:35
const STRING & name() const
Definition: network.h:138
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
virtual ~Maxpool()=default
bool DeSerialize(TFile *fp) override
Definition: maxpool.cpp:31
Definition: strngs.h:45
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: maxpool.cpp:73