tesseract  4.00.00dev
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();
33 
34  // Accessors.
35  virtual STRING spec() const {
36  STRING spec;
37  spec.add_str_int("Mp", y_scale_);
38  spec.add_str_int(",", x_scale_);
39  return spec;
40  }
41 
42  // Reads from the given file. Returns false in case of error.
43  virtual bool DeSerialize(TFile* fp);
44 
45  // Runs forward propagation of activations on the input line.
46  // See Network for a detailed discussion of the arguments.
47  virtual void Forward(bool debug, const NetworkIO& input,
48  const TransposedArray* input_transpose,
49  NetworkScratch* scratch, NetworkIO* output);
50 
51  // Runs backward propagation of errors on the deltas line.
52  // See Network for a detailed discussion of the arguments.
53  virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
54  NetworkScratch* scratch,
55  NetworkIO* back_deltas);
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_
70 
Maxpool(const STRING &name, int ni, int x_scale, int y_scale)
Definition: maxpool.cpp:24
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
virtual ~Maxpool()
Definition: maxpool.cpp:30
virtual bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas)
Definition: maxpool.cpp:76
Definition: strngs.h:45
virtual STRING spec() const
Definition: maxpool.h:35
virtual bool DeSerialize(TFile *fp)
Definition: maxpool.cpp:34
const STRING & name() const
Definition: network.h:138
virtual void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output)
Definition: maxpool.cpp:42