tesseract  4.00.00dev
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 ()
 
virtual StaticShape OutputShape (const StaticShape &input_shape) const
 
virtual STRING spec () const
 
void SetNetwork (Network *network)
 
virtual void Forward (bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output)
 
virtual bool Backward (bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas)
 
- Public Member Functions inherited from tesseract::Plumbing
 Plumbing (const STRING &name)
 
virtual ~Plumbing ()
 
virtual StaticShape InputShape () const
 
virtual bool IsPlumbingType () const
 
virtual void SetEnableTraining (TrainingState state)
 
virtual void SetNetworkFlags (uinT32 flags)
 
virtual int InitWeights (float range, TRand *randomizer)
 
virtual void ConvertToInt ()
 
virtual void SetRandomizer (TRand *randomizer)
 
virtual void AddToStack (Network *network)
 
virtual bool SetupNeedsBackprop (bool needs_backprop)
 
virtual int XScaleFactor () const
 
virtual void CacheXScaleFactor (int factor)
 
virtual void DebugWeights ()
 
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
 
virtual bool Serialize (TFile *fp) const
 
virtual bool DeSerialize (TFile *fp)
 
virtual void Update (float learning_rate, float momentum, int num_samples)
 
virtual void CountAlternators (const Network &other, double *same, double *changed) const
 
- Public Member Functions inherited from tesseract::Network
 Network ()
 
 Network (NetworkType type, const STRING &name, int ni, int no)
 
virtual ~Network ()
 
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 network_flags_
 
inT32 ni_
 
inT32 no_
 
inT32 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() const
Definition: network.h:112
NetworkType type_
Definition: network.h:285

◆ ~Reversed()

tesseract::Reversed::~Reversed ( )
virtual

Definition at line 30 of file reversed.cpp.

30  {
31 }

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Network.

Definition at line 68 of file reversed.cpp.

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

◆ Forward()

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

Reimplemented from tesseract::Network.

Definition at line 56 of file reversed.cpp.

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

◆ OutputShape()

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

Reimplemented from tesseract::Network.

Definition at line 35 of file reversed.cpp.

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

◆ SetNetwork()

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

Definition at line 49 of file reversed.cpp.

49  {
50  stack_.clear();
51  AddToStack(network);
52 }
PointerVector< Network > stack_
Definition: plumbing.h:133
virtual void AddToStack(Network *network)
Definition: plumbing.cpp:75

◆ spec()

virtual STRING tesseract::Reversed::spec ( ) const
inlinevirtual

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  }
virtual STRING spec() const
Definition: reversed.h:37
inT32 length() const
Definition: strngs.cpp:193
PointerVector< Network > stack_
Definition: plumbing.h:133
Definition: strngs.h:45
NetworkType type_
Definition: network.h:285

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