tesseract 4.1.1
Loading...
Searching...
No Matches
convolve.h
Go to the documentation of this file.
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.
19
20#ifndef TESSERACT_LSTM_CONVOLVE_H_
21#define TESSERACT_LSTM_CONVOLVE_H_
22
23#include "genericvector.h"
24#include "matrix.h"
25#include "network.h"
26
27namespace tesseract {
28
29// Makes each time-step deeper by stacking inputs over its rectangle. Does not
30// affect the size of its input. Achieves this by bringing in random values in
31// out-of-input areas.
32class Convolve : public Network {
33 public:
34 // The area of convolution is 2*half_x + 1 by 2*half_y + 1, forcing it to
35 // always be odd, so the center is the current pixel.
36 Convolve(const STRING& name, int ni, int half_x, int half_y);
37 ~Convolve() override = default;
38
39 STRING spec() const override {
41 spec.add_str_int("C", half_x_ * 2 + 1);
42 spec.add_str_int(",", half_y_ * 2 + 1);
43 return spec;
44 }
45
46 // Writes to the given file. Returns false in case of error.
47 bool Serialize(TFile* fp) const override;
48 // Reads from the given file. Returns false in case of error.
49 bool DeSerialize(TFile* fp) override;
50
51 // Runs forward propagation of activations on the input line.
52 // See Network for a detailed discussion of the arguments.
53 void Forward(bool debug, const NetworkIO& input,
54 const TransposedArray* input_transpose,
55 NetworkScratch* scratch, NetworkIO* output) override;
56
57 // Runs backward propagation of errors on the deltas line.
58 // See Network for a detailed discussion of the arguments.
59 bool Backward(bool debug, const NetworkIO& fwd_deltas,
60 NetworkScratch* scratch,
61 NetworkIO* back_deltas) override;
62
63 private:
64 void DebugWeights() override {
65 tprintf("Must override Network::DebugWeights for type %d\n", type_);
66 }
67
68 protected:
69 // Serialized data.
70 int32_t half_x_;
71 int32_t half_y_;
72};
73
74} // namespace tesseract.
75
76#endif // TESSERACT_LSTM_SUBSAMPLE_H_
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
Definition: strngs.h:45
void add_str_int(const char *str, int number)
Definition: strngs.cpp:377
~Convolve() override=default
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: convolve.cpp:50
STRING spec() const override
Definition: convolve.h:39
bool Serialize(TFile *fp) const override
Definition: convolve.cpp:34
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: convolve.cpp:84
bool DeSerialize(TFile *fp) override
Definition: convolve.cpp:41
NetworkType type_
Definition: network.h:293
const STRING & name() const
Definition: network.h:138