tesseract  5.0.0-alpha-619-ge9db
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  ~Maxpool() override = 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_
STRING::add_str_int
void add_str_int(const char *str, int number)
Definition: strngs.cpp:370
STRING
Definition: strngs.h:45
tesseract::Reconfig
Definition: reconfig.h:32
tesseract::NetworkScratch
Definition: networkscratch.h:34
tesseract::Maxpool
Definition: maxpool.h:29
tesseract::Maxpool::Forward
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: maxpool.cpp:37
GENERIC_2D_ARRAY< int >
tesseract::Maxpool::Maxpool
Maxpool(const STRING &name, int ni, int x_scale, int y_scale)
Definition: maxpool.cpp:22
tesseract::Reconfig::y_scale_
int32_t y_scale_
Definition: reconfig.h:83
tesseract::Maxpool::spec
STRING spec() const override
Definition: maxpool.h:35
tesseract::TFile
Definition: serialis.h:75
tesseract::NetworkIO
Definition: networkio.h:39
tesseract
Definition: baseapi.h:65
tesseract::Reconfig::x_scale_
int32_t x_scale_
Definition: reconfig.h:82
tesseract::Maxpool::~Maxpool
~Maxpool() override=default
reconfig.h
tesseract::Network::name
const STRING & name() const
Definition: network.h:138
tesseract::TransposedArray
Definition: weightmatrix.h:32
tesseract::Maxpool::DeSerialize
bool DeSerialize(TFile *fp) override
Definition: maxpool.cpp:29
tesseract::Maxpool::Backward
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: maxpool.cpp:71