comparison mupdf-source/thirdparty/tesseract/src/lstm/convolve.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: convolve.h
3 // Description: Convolutional layer that stacks the inputs over its rectangle
4 // and pulls in random data to fill out-of-input inputs.
5 // Output is therefore same size as its input, but deeper.
6 // Author: Ray Smith
7 //
8 // (C) Copyright 2014, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 ///////////////////////////////////////////////////////////////////////
19
20 #ifndef TESSERACT_LSTM_CONVOLVE_H_
21 #define TESSERACT_LSTM_CONVOLVE_H_
22
23 #include "matrix.h"
24 #include "network.h"
25
26 namespace tesseract {
27
28 // Makes each time-step deeper by stacking inputs over its rectangle. Does not
29 // affect the size of its input. Achieves this by bringing in random values in
30 // out-of-input areas.
31 class Convolve : public Network {
32 public:
33 // The area of convolution is 2*half_x + 1 by 2*half_y + 1, forcing it to
34 // always be odd, so the center is the current pixel.
35 TESS_API
36 Convolve(const std::string &name, int ni, int half_x, int half_y);
37 ~Convolve() override = default;
38
39 std::string spec() const override {
40 return "C" + std::to_string(half_y_ * 2 + 1) + "," + std::to_string(half_x_ * 2 + 1);
41 }
42
43 // Writes to the given file. Returns false in case of error.
44 bool Serialize(TFile *fp) const override;
45 // Reads from the given file. Returns false in case of error.
46 bool DeSerialize(TFile *fp) override;
47
48 // Runs forward propagation of activations on the input line.
49 // See Network for a detailed discussion of the arguments.
50 void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose,
51 NetworkScratch *scratch, NetworkIO *output) override;
52
53 // Runs backward propagation of errors on the deltas line.
54 // See Network for a detailed discussion of the arguments.
55 bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch,
56 NetworkIO *back_deltas) override;
57
58 private:
59 void DebugWeights() override {
60 tprintf("Must override Network::DebugWeights for type %d\n", type_);
61 }
62
63 protected:
64 // Serialized data.
65 int32_t half_x_;
66 int32_t half_y_;
67 };
68
69 } // namespace tesseract.
70
71 #endif // TESSERACT_LSTM_SUBSAMPLE_H_