tesseract  4.00.00dev
convolve.h
Go to the documentation of this file.
1 // 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 // Created: Tue Mar 18 16:45:34 PST 2014
8 //
9 // (C) Copyright 2014, Google Inc.
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
20 
21 #ifndef TESSERACT_LSTM_CONVOLVE_H_
22 #define TESSERACT_LSTM_CONVOLVE_H_
23 
24 #include "genericvector.h"
25 #include "matrix.h"
26 #include "network.h"
27 
28 namespace tesseract {
29 
30 // Makes each time-step deeper by stacking inputs over its rectangle. Does not
31 // affect the size of its input. Achieves this by bringing in random values in
32 // out-of-input areas.
33 class Convolve : public Network {
34  public:
35  // The area of convolution is 2*half_x + 1 by 2*half_y + 1, forcing it to
36  // always be odd, so the center is the current pixel.
37  Convolve(const STRING& name, int ni, int half_x, int half_y);
38  virtual ~Convolve();
39 
40  virtual STRING spec() const {
41  STRING spec;
42  spec.add_str_int("C", half_x_ * 2 + 1);
43  spec.add_str_int(",", half_y_ * 2 + 1);
44  return spec;
45  }
46 
47  // Writes to the given file. Returns false in case of error.
48  virtual bool Serialize(TFile* fp) const;
49  // Reads from the given file. Returns false in case of error.
50  virtual bool DeSerialize(TFile* fp);
51 
52  // Runs forward propagation of activations on the input line.
53  // See Network for a detailed discussion of the arguments.
54  virtual void Forward(bool debug, const NetworkIO& input,
55  const TransposedArray* input_transpose,
56  NetworkScratch* scratch, NetworkIO* output);
57 
58  // Runs backward propagation of errors on the deltas line.
59  // See Network for a detailed discussion of the arguments.
60  virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
61  NetworkScratch* scratch,
62  NetworkIO* back_deltas);
63 
64  protected:
65  // Serialized data.
68 };
69 
70 } // namespace tesseract.
71 
72 
73 #endif // TESSERACT_LSTM_SUBSAMPLE_H_
virtual STRING spec() const
Definition: convolve.h:40
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
virtual void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output)
Definition: convolve.cpp:54
int32_t inT32
Definition: host.h:38
virtual ~Convolve()
Definition: convolve.cpp:33
virtual bool Serialize(TFile *fp) const
Definition: convolve.cpp:37
virtual bool DeSerialize(TFile *fp)
Definition: convolve.cpp:45
Definition: strngs.h:45
const STRING & name() const
Definition: network.h:138
virtual bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas)
Definition: convolve.cpp:88
Convolve(const STRING &name, int ni, int half_x, int half_y)
Definition: convolve.cpp:28