tesseract  5.0.0
tesseract::Reconfig Class Reference

#include <reconfig.h>

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

Public Member Functions

TESS_API Reconfig (const char *name, int ni, int x_scale, int y_scale)
 
 ~Reconfig () override=default
 
StaticShape OutputShape (const StaticShape &input_shape) const override
 
std::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 std::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 std::string & name () 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 ([[maybe_unused]] int old_no, [[maybe_unused]] const std::vector< int > &code_map)
 
virtual void ConvertToInt ()
 
virtual void SetRandomizer (TRand *randomizer)
 
virtual bool SetupNeedsBackprop (bool needs_backprop)
 
virtual void CacheXScaleFactor ([[maybe_unused]] int factor)
 
virtual void Update ([[maybe_unused]] float learning_rate, [[maybe_unused]] float momentum, [[maybe_unused]] float adam_beta, [[maybe_unused]] int num_samples)
 
virtual void CountAlternators ([[maybe_unused]] const Network &other, [[maybe_unused]] TFloat *same, [[maybe_unused]] TFloat *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_
 
std::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 (Image pix, ScrollView *window)
 
- Protected Member Functions inherited from tesseract::Network
TFloat Random (TFloat range)
 

Detailed Description

Definition at line 31 of file reconfig.h.

Constructor & Destructor Documentation

◆ Reconfig()

tesseract::Reconfig::Reconfig ( const char *  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)
26  , y_scale_(y_scale) {}
@ NT_RECONFIG
Definition: network.h:53
const std::string & name() const
Definition: network.h:140
int32_t y_scale_
Definition: reconfig.h:78
int32_t x_scale_
Definition: reconfig.h:77

◆ ~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 93 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(), src_index.index(FD_BATCH),
100  src_index.index(FD_HEIGHT) * y_scale_,
101  src_index.index(FD_WIDTH) * x_scale_);
102  // Unstack x_scale_ groups of y_scale_ inputs that are together.
103  for (int x = 0; x < x_scale_; ++x) {
104  for (int y = 0; y < y_scale_; ++y) {
105  StrideMap::Index dest_xy(dest_index);
106  if (dest_xy.AddOffset(x, FD_WIDTH) && dest_xy.AddOffset(y, FD_HEIGHT)) {
107  back_deltas->CopyTimeStepGeneral(dest_xy.t(), 0, ni_, fwd_deltas, in_t,
108  (x * y_scale_ + y) * ni_);
109  }
110  }
111  }
112  } while (src_index.Increment());
113  return needs_to_backprop_;
114 }
@ FD_WIDTH
Definition: stridemap.h:35
@ FD_BATCH
Definition: stridemap.h:33
@ FD_HEIGHT
Definition: stridemap.h:34
bool needs_to_backprop_
Definition: network.h:302
StrideMap back_map_
Definition: reconfig.h:75

◆ DeSerialize()

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

Implements tesseract::Network.

Definition at line 56 of file reconfig.cpp.

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

◆ 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 69 of file reconfig.cpp.

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

◆ 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  }
37  return result;
38 }
@ NT_MAXPOOL
Definition: network.h:46
NetworkType type_
Definition: network.h:300

◆ 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) && fp->Serialize(&x_scale_) && fp->Serialize(&y_scale_);
53 }
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:158

◆ spec()

std::string tesseract::Reconfig::spec ( ) const
inlineoverridevirtual

Reimplemented from tesseract::Network.

Definition at line 41 of file reconfig.h.

41  {
42  return "S" + std::to_string(y_scale_) + "," + std::to_string(x_scale_);
43  }

◆ 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 }

Member Data Documentation

◆ back_map_

StrideMap tesseract::Reconfig::back_map_
protected

Definition at line 75 of file reconfig.h.

◆ x_scale_

int32_t tesseract::Reconfig::x_scale_
protected

Definition at line 77 of file reconfig.h.

◆ y_scale_

int32_t tesseract::Reconfig::y_scale_
protected

Definition at line 78 of file reconfig.h.


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