tesseract  4.00.00dev
reconfig.h
Go to the documentation of this file.
1 // File: reconfig.h
3 // Description: Network layer that reconfigures the scaling vs feature
4 // depth.
5 // Author: Ray Smith
6 // Created: Wed Feb 26 15:37:42 PST 2014
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 #ifndef TESSERACT_LSTM_RECONFIG_H_
20 #define TESSERACT_LSTM_RECONFIG_H_
21 
22 
23 #include "genericvector.h"
24 #include "matrix.h"
25 #include "network.h"
26 
27 namespace tesseract {
28 
29 // Reconfigures (Shrinks) the inputs by concatenating an x_scale by y_scale tile
30 // of inputs together, producing a single, deeper output per tile.
31 // Note that fractional parts are truncated for efficiency, so make sure the
32 // input stride is a multiple of the y_scale factor!
33 class Reconfig : public Network {
34  public:
35  Reconfig(const STRING& name, int ni, int x_scale, int y_scale);
36  virtual ~Reconfig();
37 
38  // Returns the shape output from the network given an input shape (which may
39  // be partially unknown ie zero).
40  virtual StaticShape OutputShape(const StaticShape& input_shape) const;
41 
42  virtual STRING spec() const {
43  STRING spec;
44  spec.add_str_int("S", y_scale_);
45  spec.add_str_int(",", x_scale_);
46  return spec;
47  }
48 
49  // Returns an integer reduction factor that the network applies to the
50  // time sequence. Assumes that any 2-d is already eliminated. Used for
51  // scaling bounding boxes of truth data.
52  // WARNING: if GlobalMinimax is used to vary the scale, this will return
53  // the last used scale factor. Call it before any forward, and it will return
54  // the minimum scale factor of the paths through the GlobalMinimax.
55  virtual int XScaleFactor() const;
56 
57  // Writes to the given file. Returns false in case of error.
58  virtual bool Serialize(TFile* fp) const;
59  // Reads from the given file. Returns false in case of error.
60  virtual bool DeSerialize(TFile* fp);
61 
62  // Runs forward propagation of activations on the input line.
63  // See Network for a detailed discussion of the arguments.
64  virtual void Forward(bool debug, const NetworkIO& input,
65  const TransposedArray* input_transpose,
66  NetworkScratch* scratch, NetworkIO* output);
67 
68  // Runs backward propagation of errors on the deltas line.
69  // See Network for a detailed discussion of the arguments.
70  virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
71  NetworkScratch* scratch,
72  NetworkIO* back_deltas);
73 
74  protected:
75  // Non-serialized data used to store parameters between forward and back.
77  // Serialized data.
80 };
81 
82 } // namespace tesseract.
83 
84 
85 #endif // TESSERACT_LSTM_SUBSAMPLE_H_
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
int32_t inT32
Definition: host.h:38
virtual bool Serialize(TFile *fp) const
Definition: reconfig.cpp:54
Reconfig(const STRING &name, int ni, int x_scale, int y_scale)
Definition: reconfig.cpp:24
StrideMap back_map_
Definition: reconfig.h:76
virtual bool DeSerialize(TFile *fp)
Definition: reconfig.cpp:62
virtual int XScaleFactor() const
Definition: reconfig.cpp:49
virtual ~Reconfig()
Definition: reconfig.cpp:29
virtual bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas)
Definition: reconfig.cpp:97
Definition: strngs.h:45
virtual void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output)
Definition: reconfig.cpp:71
virtual StaticShape OutputShape(const StaticShape &input_shape) const
Definition: reconfig.cpp:34
virtual STRING spec() const
Definition: reconfig.h:42
const STRING & name() const
Definition: network.h:138