tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
maxpool.h
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_);
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  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.
60 };
61 
62 
63 } // namespace tesseract.
64 
65 
66 
67 
68 
69 #endif // TESSERACT_LSTM_MAXPOOL_H_
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
Maxpool(const STRING &name, int ni, int x_scale, int y_scale)
Definition: maxpool.cpp:24
virtual ~Maxpool()=default
Definition: networkscratch.h:36
int32_t y_scale_
Definition: reconfig.h:79
Definition: serialis.h:77
Definition: maxpool.h:29
Definition: baseapi.cpp:94
const STRING & name() const
Definition: network.h:138
Definition: weightmatrix.h:33
Definition: strngs.h:45
GENERIC_2D_ARRAY< int > maxes_
Definition: maxpool.h:59
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: maxpool.cpp:73
int32_t x_scale_
Definition: reconfig.h:78
Definition: networkio.h:39
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: maxpool.cpp:39
Definition: reconfig.h:33
bool DeSerialize(TFile *fp) override
Definition: maxpool.cpp:31
STRING spec() const override
Definition: maxpool.h:35