tesseract  4.00.00dev
tesseract::Reconfig Class Reference

#include <reconfig.h>

Inheritance diagram for tesseract::Reconfig:
tesseract::Network tesseract::Maxpool

Public Member Functions

 Reconfig (const STRING &name, int ni, int x_scale, int y_scale)
 
virtual ~Reconfig ()
 
virtual StaticShape OutputShape (const StaticShape &input_shape) const
 
virtual STRING spec () const
 
virtual int XScaleFactor () const
 
virtual bool Serialize (TFile *fp) const
 
virtual bool DeSerialize (TFile *fp)
 
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::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
 
virtual StaticShape InputShape () const
 
const STRINGname () const
 
bool TestFlag (NetworkFlags flag) 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 bool SetupNeedsBackprop (bool needs_backprop)
 
virtual void CacheXScaleFactor (int factor)
 
virtual void DebugWeights ()
 
virtual void Update (float learning_rate, float momentum, int num_samples)
 
virtual void CountAlternators (const Network &other, double *same, double *changed) const
 
void DisplayForward (const NetworkIO &matrix)
 
void DisplayBackward (const NetworkIO &matrix)
 

Protected Attributes

StrideMap back_map_
 
inT32 x_scale_
 
inT32 y_scale_
 
- 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_
 

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)
 
- Static Protected Attributes inherited from tesseract::Network
static char const *const kTypeNames [NT_COUNT]
 

Detailed Description

Definition at line 33 of file reconfig.h.

Constructor & Destructor Documentation

◆ Reconfig()

tesseract::Reconfig::Reconfig ( const STRING name,
int  ni,
int  x_scale,
int  y_scale 
)

Definition at line 24 of file reconfig.cpp.

25  : Network(NT_RECONFIG, name, ni, ni * x_scale * y_scale),
26  x_scale_(x_scale), y_scale_(y_scale) {
27 }

◆ ~Reconfig()

tesseract::Reconfig::~Reconfig ( )
virtual

Definition at line 29 of file reconfig.cpp.

29  {
30 }

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Network.

Reimplemented in tesseract::Maxpool.

Definition at line 97 of file reconfig.cpp.

99  {
100  back_deltas->ResizeToMap(fwd_deltas.int_mode(), back_map_, ni_);
101  StrideMap::Index src_index(fwd_deltas.stride_map());
102  do {
103  int in_t = src_index.t();
104  StrideMap::Index dest_index(back_deltas->stride_map(),
105  src_index.index(FD_BATCH),
106  src_index.index(FD_HEIGHT) * y_scale_,
107  src_index.index(FD_WIDTH) * x_scale_);
108  // Unstack x_scale_ groups of y_scale_ inputs that are together.
109  for (int x = 0; x < x_scale_; ++x) {
110  for (int y = 0; y < y_scale_; ++y) {
111  StrideMap::Index dest_xy(dest_index);
112  if (dest_xy.AddOffset(x, FD_WIDTH) && dest_xy.AddOffset(y, FD_HEIGHT)) {
113  back_deltas->CopyTimeStepGeneral(dest_xy.t(), 0, ni_, fwd_deltas,
114  in_t, (x * y_scale_ + y) * ni_);
115  }
116  }
117  }
118  } while (src_index.Increment());
119  return needs_to_backprop_;
120 }
bool needs_to_backprop_
Definition: network.h:287
StrideMap back_map_
Definition: reconfig.h:76

◆ DeSerialize()

bool tesseract::Reconfig::DeSerialize ( TFile fp)
virtual

Reimplemented from tesseract::Network.

Reimplemented in tesseract::Maxpool.

Definition at line 62 of file reconfig.cpp.

62  {
63  if (fp->FReadEndian(&x_scale_, sizeof(x_scale_), 1) != 1) return false;
64  if (fp->FReadEndian(&y_scale_, sizeof(y_scale_), 1) != 1) return false;
65  no_ = ni_ * x_scale_ * y_scale_;
66  return true;
67 }

◆ Forward()

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

Reimplemented from tesseract::Network.

Reimplemented in tesseract::Maxpool.

Definition at line 71 of file reconfig.cpp.

73  {
74  output->ResizeScaled(input, x_scale_, y_scale_, no_);
75  back_map_ = input.stride_map();
76  StrideMap::Index dest_index(output->stride_map());
77  do {
78  int out_t = dest_index.t();
79  StrideMap::Index src_index(input.stride_map(), dest_index.index(FD_BATCH),
80  dest_index.index(FD_HEIGHT) * y_scale_,
81  dest_index.index(FD_WIDTH) * x_scale_);
82  // Stack x_scale_ groups of y_scale_ inputs together.
83  for (int x = 0; x < x_scale_; ++x) {
84  for (int y = 0; y < y_scale_; ++y) {
85  StrideMap::Index src_xy(src_index);
86  if (src_xy.AddOffset(x, FD_WIDTH) && src_xy.AddOffset(y, FD_HEIGHT)) {
87  output->CopyTimeStepGeneral(out_t, (x * y_scale_ + y) * ni_, ni_,
88  input, src_xy.t(), 0);
89  }
90  }
91  }
92  } while (dest_index.Increment());
93 }
StrideMap back_map_
Definition: reconfig.h:76

◆ OutputShape()

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

Reimplemented from tesseract::Network.

Definition at line 34 of file reconfig.cpp.

34  {
35  StaticShape result = input_shape;
36  result.set_height(result.height() / y_scale_);
37  result.set_width(result.width() / x_scale_);
38  if (type_ != NT_MAXPOOL)
39  result.set_depth(result.depth() * y_scale_ * x_scale_);
40  return result;
41 }
NetworkType type_
Definition: network.h:285

◆ Serialize()

bool tesseract::Reconfig::Serialize ( TFile fp) const
virtual

Reimplemented from tesseract::Network.

Definition at line 54 of file reconfig.cpp.

54  {
55  if (!Network::Serialize(fp)) return false;
56  if (fp->FWrite(&x_scale_, sizeof(x_scale_), 1) != 1) return false;
57  if (fp->FWrite(&y_scale_, sizeof(y_scale_), 1) != 1) return false;
58  return true;
59 }
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:153

◆ spec()

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

Reimplemented from tesseract::Network.

Reimplemented in tesseract::Maxpool.

Definition at line 42 of file reconfig.h.

42  {
43  STRING spec;
44  spec.add_str_int("S", y_scale_);
45  spec.add_str_int(",", x_scale_);
46  return spec;
47  }
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
Definition: strngs.h:45
virtual STRING spec() const
Definition: reconfig.h:42

◆ XScaleFactor()

int tesseract::Reconfig::XScaleFactor ( ) const
virtual

Reimplemented from tesseract::Network.

Definition at line 49 of file reconfig.cpp.

49  {
50  return x_scale_;
51 }

Member Data Documentation

◆ back_map_

StrideMap tesseract::Reconfig::back_map_
protected

Definition at line 76 of file reconfig.h.

◆ x_scale_

inT32 tesseract::Reconfig::x_scale_
protected

Definition at line 78 of file reconfig.h.

◆ y_scale_

inT32 tesseract::Reconfig::y_scale_
protected

Definition at line 79 of file reconfig.h.


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