tesseract  4.0.0-1-g2a2b
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 ()=default
 
StaticShape OutputShape (const StaticShape &input_shape) const override
 
STRING spec () const override
 
int XScaleFactor () const override
 
bool Serialize (TFile *fp) const override
 
bool DeSerialize (TFile *fp) override
 
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::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
 
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_t flags)
 
virtual int InitWeights (float range, TRand *randomizer)
 
virtual int RemapOutputs (int old_no, const std::vector< int > &code_map)
 
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, float adam_beta, 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_t x_scale_
 
int32_t y_scale_
 
- 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_
 

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 }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
const STRING & name() const
Definition: network.h:138

◆ ~Reconfig()

virtual tesseract::Reconfig::~Reconfig ( )
virtualdefault

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Network.

Definition at line 93 of file reconfig.cpp.

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

◆ DeSerialize()

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

Reimplemented from tesseract::Network.

Definition at line 58 of file reconfig.cpp.

58  {
59  if (!fp->DeSerialize(&x_scale_)) return false;
60  if (!fp->DeSerialize(&y_scale_)) return false;
61  no_ = ni_ * x_scale_ * y_scale_;
62  return true;
63 }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78

◆ Forward()

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

Reimplemented from tesseract::Network.

Definition at line 67 of file reconfig.cpp.

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

◆ OutputShape()

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

Reimplemented from tesseract::Network.

Definition at line 31 of file reconfig.cpp.

31  {
32  StaticShape result = input_shape;
33  result.set_height(result.height() / y_scale_);
34  result.set_width(result.width() / x_scale_);
35  if (type_ != NT_MAXPOOL)
36  result.set_depth(result.depth() * y_scale_ * x_scale_);
37  return result;
38 }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
NetworkType type_
Definition: network.h:299

◆ Serialize()

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

Reimplemented from tesseract::Network.

Definition at line 51 of file reconfig.cpp.

51  {
52  return Network::Serialize(fp) &&
53  fp->Serialize(&x_scale_) &&
54  fp->Serialize(&y_scale_);
55 }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:151

◆ spec()

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

Reimplemented from tesseract::Network.

Definition at line 42 of file reconfig.h.

42  {
43  STRING spec;
46  return spec;
47  }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
STRING spec() const override
Definition: reconfig.h:42
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
Definition: strngs.h:45

◆ XScaleFactor()

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

Reimplemented from tesseract::Network.

Definition at line 46 of file reconfig.cpp.

46  {
47  return x_scale_;
48 }
int32_t x_scale_
Definition: reconfig.h:78

Member Data Documentation

◆ back_map_

StrideMap tesseract::Reconfig::back_map_
protected

Definition at line 76 of file reconfig.h.

◆ x_scale_

int32_t tesseract::Reconfig::x_scale_
protected

Definition at line 78 of file reconfig.h.

◆ y_scale_

int32_t tesseract::Reconfig::y_scale_
protected

Definition at line 79 of file reconfig.h.


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