tesseract  4.0.0-1-g2a2b
tesseract::Reversed Class Reference

#include <reversed.h>

Inheritance diagram for tesseract::Reversed:
tesseract::Plumbing tesseract::Network

Public Member Functions

 Reversed (const STRING &name, NetworkType type)
 
virtual ~Reversed ()=default
 
StaticShape OutputShape (const StaticShape &input_shape) const override
 
STRING spec () const override
 
void SetNetwork (Network *network)
 
void Forward (bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
 
bool Backward (bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
 
- Public Member Functions inherited from tesseract::Plumbing
 Plumbing (const STRING &name)
 
virtual ~Plumbing ()=default
 
StaticShape InputShape () const override
 
bool IsPlumbingType () const override
 
void SetEnableTraining (TrainingState state) override
 
void SetNetworkFlags (uint32_t flags) override
 
int InitWeights (float range, TRand *randomizer) override
 
int RemapOutputs (int old_no, const std::vector< int > &code_map) override
 
void ConvertToInt () override
 
void SetRandomizer (TRand *randomizer) override
 
virtual void AddToStack (Network *network)
 
bool SetupNeedsBackprop (bool needs_backprop) override
 
int XScaleFactor () const override
 
void CacheXScaleFactor (int factor) override
 
void DebugWeights () override
 
const PointerVector< Network > & stack () const
 
void EnumerateLayers (const STRING *prefix, GenericVector< STRING > *layers) const
 
NetworkGetLayer (const char *id) const
 
float LayerLearningRate (const char *id) const
 
void ScaleLayerLearningRate (const char *id, double factor)
 
float * LayerLearningRatePtr (const char *id) const
 
bool Serialize (TFile *fp) const override
 
bool DeSerialize (TFile *fp) override
 
void Update (float learning_rate, float momentum, float adam_beta, int num_samples) override
 
void CountAlternators (const Network &other, double *same, double *changed) const override
 
- Public Member Functions inherited from tesseract::Network
 Network ()
 
 Network (NetworkType type, const STRING &name, int ni, int no)
 
virtual ~Network ()=default
 
NetworkType type () const
 
bool IsTraining () const
 
bool needs_to_backprop () const
 
int num_weights () const
 
int NumInputs () const
 
int NumOutputs () const
 
const STRINGname () const
 
bool TestFlag (NetworkFlags flag) const
 
void DisplayForward (const NetworkIO &matrix)
 
void DisplayBackward (const NetworkIO &matrix)
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::Network
static NetworkCreateFromFile (TFile *fp)
 
static void ClearWindow (bool tess_coords, const char *window_name, int width, int height, ScrollView **window)
 
static int DisplayImage (Pix *pix, ScrollView *window)
 
- Protected Member Functions inherited from tesseract::Network
double Random (double range)
 
- Protected Attributes inherited from tesseract::Plumbing
PointerVector< Networkstack_
 
GenericVector< float > learning_rates_
 
- Protected Attributes inherited from tesseract::Network
NetworkType type_
 
TrainingState training_
 
bool needs_to_backprop_
 
int32_t network_flags_
 
int32_t ni_
 
int32_t no_
 
int32_t num_weights_
 
STRING name_
 
ScrollViewforward_win_
 
ScrollViewbackward_win_
 
TRandrandomizer_
 
- Static Protected Attributes inherited from tesseract::Network
static char const *const kTypeNames [NT_COUNT]
 

Detailed Description

Definition at line 28 of file reversed.h.

Constructor & Destructor Documentation

◆ Reversed()

tesseract::Reversed::Reversed ( const STRING name,
NetworkType  type 
)
explicit

Definition at line 27 of file reversed.cpp.

27  : Plumbing(name) {
28  type_ = type;
29 }
Plumbing(const STRING &name)
Definition: plumbing.cpp:25
NetworkType type_
Definition: network.h:299
const STRING & name() const
Definition: network.h:138
NetworkType type() const
Definition: network.h:112

◆ ~Reversed()

virtual tesseract::Reversed::~Reversed ( )
virtualdefault

Member Function Documentation

◆ Backward()

bool tesseract::Reversed::Backward ( bool  debug,
const NetworkIO fwd_deltas,
NetworkScratch scratch,
NetworkIO back_deltas 
)
overridevirtual

Reimplemented from tesseract::Network.

Definition at line 66 of file reversed.cpp.

68  {
69  NetworkScratch::IO rev_input(fwd_deltas, scratch);
70  ReverseData(fwd_deltas, rev_input);
71  NetworkScratch::IO rev_output(fwd_deltas, scratch);
72  if (stack_[0]->Backward(debug, *rev_input, scratch, rev_output)) {
73  ReverseData(*rev_output, back_deltas);
74  return true;
75  }
76  return false;
77 }
PointerVector< Network > stack_
Definition: plumbing.h:136
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
Definition: reversed.cpp:66

◆ Forward()

void tesseract::Reversed::Forward ( bool  debug,
const NetworkIO input,
const TransposedArray input_transpose,
NetworkScratch scratch,
NetworkIO output 
)
overridevirtual

Reimplemented from tesseract::Network.

Definition at line 54 of file reversed.cpp.

56  {
57  NetworkScratch::IO rev_input(input, scratch);
58  ReverseData(input, rev_input);
59  NetworkScratch::IO rev_output(input, scratch);
60  stack_[0]->Forward(debug, *rev_input, nullptr, scratch, rev_output);
61  ReverseData(*rev_output, output);
62 }
PointerVector< Network > stack_
Definition: plumbing.h:136

◆ OutputShape()

StaticShape tesseract::Reversed::OutputShape ( const StaticShape input_shape) const
overridevirtual

Reimplemented from tesseract::Network.

Definition at line 33 of file reversed.cpp.

33  {
34  if (type_ == NT_XYTRANSPOSE) {
35  StaticShape x_shape(input_shape);
36  x_shape.set_width(input_shape.height());
37  x_shape.set_height(input_shape.width());
38  x_shape = stack_[0]->OutputShape(x_shape);
39  x_shape.SetShape(x_shape.batch(), x_shape.width(), x_shape.height(),
40  x_shape.depth());
41  return x_shape;
42  }
43  return stack_[0]->OutputShape(input_shape);
44 }
NetworkType type_
Definition: network.h:299
PointerVector< Network > stack_
Definition: plumbing.h:136

◆ SetNetwork()

void tesseract::Reversed::SetNetwork ( Network network)

Definition at line 47 of file reversed.cpp.

47  {
48  stack_.clear();
49  AddToStack(network);
50 }
PointerVector< Network > stack_
Definition: plumbing.h:136
virtual void AddToStack(Network *network)
Definition: plumbing.cpp:82

◆ spec()

STRING tesseract::Reversed::spec ( ) const
inlineoverridevirtual

Reimplemented from tesseract::Plumbing.

Definition at line 37 of file reversed.h.

37  {
38  STRING spec(type_ == NT_XREVERSED ? "Rx"
39  : (type_ == NT_YREVERSED ? "Ry" : "Txy"));
40  // For most simple cases, we will output Rx<net> or Ry<net> where <net> is
41  // the network in stack_[0], but in the special case that <net> is an
42  // LSTM, we will just output the LSTM's spec modified to take the reversal
43  // into account. This is because when the user specified Lfy64, we actually
44  // generated TxyLfx64, and if the user specified Lrx64 we actually
45  // generated RxLfx64, and we want to display what the user asked for.
46  STRING net_spec = stack_[0]->spec();
47  if (net_spec[0] == 'L') {
48  // Setup a from and to character according to the type of the reversal
49  // such that the LSTM spec gets modified to the spec that the user
50  // asked for
51  char from = 'f';
52  char to = 'r';
53  if (type_ == NT_XYTRANSPOSE) {
54  from = 'x';
55  to = 'y';
56  }
57  // Change the from char to the to char.
58  for (int i = 0; i < net_spec.length(); ++i) {
59  if (net_spec[i] == from) net_spec[i] = to;
60  }
61  return net_spec;
62  }
63  spec += net_spec;
64  return spec;
65  }
NetworkType type_
Definition: network.h:299
PointerVector< Network > stack_
Definition: plumbing.h:136
Definition: strngs.h:45
int32_t length() const
Definition: strngs.cpp:191
STRING spec() const override
Definition: reversed.h:37

The documentation for this class was generated from the following files: