tesseract 4.1.1
Loading...
Searching...
No Matches
reconfig.h
Go to the documentation of this file.
1
2// File: reconfig.h
3// Description: Network layer that reconfigures the scaling vs feature
4// depth.
5// Author: Ray Smith
6//
7// (C) Copyright 2014, Google Inc.
8// Licensed under the Apache License, Version 2.0 (the "License");
9// you may not use this file except in compliance with the License.
10// You may obtain a copy of the License at
11// http://www.apache.org/licenses/LICENSE-2.0
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
18
19#ifndef TESSERACT_LSTM_RECONFIG_H_
20#define TESSERACT_LSTM_RECONFIG_H_
21
22#include "genericvector.h"
23#include "matrix.h"
24#include "network.h"
25
26namespace tesseract {
27
28// Reconfigures (Shrinks) the inputs by concatenating an x_scale by y_scale tile
29// of inputs together, producing a single, deeper output per tile.
30// Note that fractional parts are truncated for efficiency, so make sure the
31// input stride is a multiple of the y_scale factor!
32class Reconfig : public Network {
33 public:
34 Reconfig(const STRING& name, int ni, int x_scale, int y_scale);
35 ~Reconfig() override = default;
36
37 // Returns the shape output from the network given an input shape (which may
38 // be partially unknown ie zero).
39 StaticShape OutputShape(const StaticShape& input_shape) const override;
40
41 STRING spec() const override {
45 return spec;
46 }
47
48 // Returns an integer reduction factor that the network applies to the
49 // time sequence. Assumes that any 2-d is already eliminated. Used for
50 // scaling bounding boxes of truth data.
51 // WARNING: if GlobalMinimax is used to vary the scale, this will return
52 // the last used scale factor. Call it before any forward, and it will return
53 // the minimum scale factor of the paths through the GlobalMinimax.
54 int XScaleFactor() const override;
55
56 // Writes to the given file. Returns false in case of error.
57 bool Serialize(TFile* fp) const override;
58 // Reads from the given file. Returns false in case of error.
59 bool DeSerialize(TFile* fp) override;
60
61 // Runs forward propagation of activations on the input line.
62 // See Network for a detailed discussion of the arguments.
63 void Forward(bool debug, const NetworkIO& input,
64 const TransposedArray* input_transpose,
65 NetworkScratch* scratch, NetworkIO* output) override;
66
67 // Runs backward propagation of errors on the deltas line.
68 // See Network for a detailed discussion of the arguments.
69 bool Backward(bool debug, const NetworkIO& fwd_deltas,
70 NetworkScratch* scratch,
71 NetworkIO* back_deltas) override;
72
73 private:
74 void DebugWeights() override {
75 tprintf("Must override Network::DebugWeights for type %d\n", type_);
76 }
77
78 protected:
79 // Non-serialized data used to store parameters between forward and back.
81 // Serialized data.
82 int32_t x_scale_;
83 int32_t y_scale_;
84};
85
86} // namespace tesseract.
87
88#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
NetworkType type_
Definition: network.h:293
const STRING & name() const
Definition: network.h:138
StrideMap back_map_
Definition: reconfig.h:80
bool DeSerialize(TFile *fp) override
Definition: reconfig.cpp:57
~Reconfig() override=default
int XScaleFactor() const override
Definition: reconfig.cpp:45
bool Serialize(TFile *fp) const override
Definition: reconfig.cpp:50
int32_t y_scale_
Definition: reconfig.h:83
STRING spec() const override
Definition: reconfig.h:41
StaticShape OutputShape(const StaticShape &input_shape) const override
Definition: reconfig.cpp:30
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: reconfig.cpp:92
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Definition: reconfig.cpp:66
int32_t x_scale_
Definition: reconfig.h:82