tesseract  5.0.0-alpha-619-ge9db
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)
 
 ~Reconfig () override=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 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)
 

Detailed Description

Definition at line 32 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 23 of file reconfig.cpp.

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

◆ ~Reconfig()

tesseract::Reconfig::~Reconfig ( )
overridedefault

Member Function Documentation

◆ Backward()

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

Implements tesseract::Network.

Definition at line 92 of file reconfig.cpp.

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

◆ DeSerialize()

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

Implements tesseract::Network.

Definition at line 57 of file reconfig.cpp.

57  {
58  if (!fp->DeSerialize(&x_scale_)) return false;
59  if (!fp->DeSerialize(&y_scale_)) return false;
60  no_ = ni_ * x_scale_ * y_scale_;
61  return true;
62 }

◆ Forward()

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

Implements tesseract::Network.

Definition at line 66 of file reconfig.cpp.

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

◆ OutputShape()

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

Reimplemented from tesseract::Network.

Definition at line 30 of file reconfig.cpp.

30  {
31  StaticShape result = input_shape;
32  result.set_height(result.height() / y_scale_);
33  result.set_width(result.width() / x_scale_);
34  if (type_ != NT_MAXPOOL)
35  result.set_depth(result.depth() * y_scale_ * x_scale_);
36  return result;
37 }

◆ Serialize()

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

Reimplemented from tesseract::Network.

Definition at line 50 of file reconfig.cpp.

50  {
51  return Network::Serialize(fp) &&
52  fp->Serialize(&x_scale_) &&
53  fp->Serialize(&y_scale_);
54 }

◆ spec()

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

Reimplemented from tesseract::Network.

Definition at line 41 of file reconfig.h.

41  {
42  STRING spec;
45  return spec;
46  }

◆ XScaleFactor()

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

Reimplemented from tesseract::Network.

Definition at line 45 of file reconfig.cpp.

45  {
46  return x_scale_;
47 }

Member Data Documentation

◆ back_map_

StrideMap tesseract::Reconfig::back_map_
protected

Definition at line 80 of file reconfig.h.

◆ x_scale_

int32_t tesseract::Reconfig::x_scale_
protected

Definition at line 82 of file reconfig.h.

◆ y_scale_

int32_t tesseract::Reconfig::y_scale_
protected

Definition at line 83 of file reconfig.h.


The documentation for this class was generated from the following files:
tesseract::Reconfig::spec
STRING spec() const override
Definition: reconfig.h:41
STRING::add_str_int
void add_str_int(const char *str, int number)
Definition: strngs.cpp:370
STRING
Definition: strngs.h:45
tesseract::Network::needs_to_backprop_
bool needs_to_backprop_
Definition: network.h:295
tesseract::Reconfig::y_scale_
int32_t y_scale_
Definition: reconfig.h:83
tesseract::Network::type_
NetworkType type_
Definition: network.h:293
tesseract::FD_WIDTH
Definition: stridemap.h:35
tesseract::Reconfig::x_scale_
int32_t x_scale_
Definition: reconfig.h:82
tesseract::Network::name
const STRING & name() const
Definition: network.h:138
tesseract::FD_HEIGHT
Definition: stridemap.h:34
tesseract::Network::Serialize
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:151
tesseract::Reconfig::back_map_
StrideMap back_map_
Definition: reconfig.h:80
tesseract::FD_BATCH
Definition: stridemap.h:33
tesseract::Network::no_
int32_t no_
Definition: network.h:298
tesseract::Network::ni_
int32_t ni_
Definition: network.h:297
tesseract::NT_MAXPOOL
Definition: network.h:48
tesseract::NT_RECONFIG
Definition: network.h:55
tesseract::Network::Network
Network()
Definition: network.cpp:76