comparison mupdf-source/thirdparty/tesseract/src/lstm/maxpool.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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 ~Maxpool() override = default;
33
34 // Accessors.
35 std::string spec() const override {
36 return "Mp" + std::to_string(y_scale_) + "," + std::to_string(x_scale_);
37 }
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_