tesseract  4.0.0-1-g2a2b
tesseract::Convolve Class Reference

#include <convolve.h>

Inheritance diagram for tesseract::Convolve:
tesseract::Network

Public Member Functions

 Convolve (const STRING &name, int ni, int half_x, int half_y)
 
virtual ~Convolve ()=default
 
STRING spec () 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
 
virtual StaticShape OutputShape (const StaticShape &input_shape) 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 int XScaleFactor () const
 
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

int32_t half_x_
 
int32_t half_y_
 
- 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 convolve.h.

Constructor & Destructor Documentation

◆ Convolve()

tesseract::Convolve::Convolve ( const STRING name,
int  ni,
int  half_x,
int  half_y 
)

Definition at line 28 of file convolve.cpp.

29  : Network(NT_CONVOLVE, name, ni, ni * (2*half_x + 1) * (2*half_y + 1)),
30  half_x_(half_x), half_y_(half_y) {
31 }
const STRING & name() const
Definition: network.h:138

◆ ~Convolve()

virtual tesseract::Convolve::~Convolve ( )
virtualdefault

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Network.

Definition at line 84 of file convolve.cpp.

86  {
87  back_deltas->Resize(fwd_deltas, ni_);
88  NetworkScratch::IO delta_sum;
89  delta_sum.ResizeFloat(fwd_deltas, ni_, scratch);
90  delta_sum->Zero();
91  int y_scale = 2 * half_y_ + 1;
92  StrideMap::Index src_index(fwd_deltas.stride_map());
93  do {
94  // Stack x_scale groups of y_scale * ni_ inputs together.
95  int t = src_index.t();
96  int out_ix = 0;
97  for (int x = -half_x_; x <= half_x_; ++x, out_ix += y_scale * ni_) {
98  StrideMap::Index x_index(src_index);
99  if (x_index.AddOffset(x, FD_WIDTH)) {
100  int out_iy = out_ix;
101  for (int y = -half_y_; y <= half_y_; ++y, out_iy += ni_) {
102  StrideMap::Index y_index(x_index);
103  if (y_index.AddOffset(y, FD_HEIGHT)) {
104  fwd_deltas.AddTimeStepPart(t, out_iy, ni_,
105  delta_sum->f(y_index.t()));
106  }
107  }
108  }
109  }
110  } while (src_index.Increment());
111  back_deltas->CopyAll(*delta_sum);
112  return true;
113 }

◆ DeSerialize()

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

Reimplemented from tesseract::Network.

Definition at line 41 of file convolve.cpp.

41  {
42  if (!fp->DeSerialize(&half_x_)) return false;
43  if (!fp->DeSerialize(&half_y_)) return false;
44  no_ = ni_ * (2*half_x_ + 1) * (2*half_y_ + 1);
45  return true;
46 }

◆ Forward()

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

Reimplemented from tesseract::Network.

Definition at line 50 of file convolve.cpp.

52  {
53  output->Resize(input, no_);
54  int y_scale = 2 * half_y_ + 1;
55  StrideMap::Index dest_index(output->stride_map());
56  do {
57  // Stack x_scale groups of y_scale * ni_ inputs together.
58  int t = dest_index.t();
59  int out_ix = 0;
60  for (int x = -half_x_; x <= half_x_; ++x, out_ix += y_scale * ni_) {
61  StrideMap::Index x_index(dest_index);
62  if (!x_index.AddOffset(x, FD_WIDTH)) {
63  // This x is outside the image.
64  output->Randomize(t, out_ix, y_scale * ni_, randomizer_);
65  } else {
66  int out_iy = out_ix;
67  for (int y = -half_y_; y <= half_y_; ++y, out_iy += ni_) {
68  StrideMap::Index y_index(x_index);
69  if (!y_index.AddOffset(y, FD_HEIGHT)) {
70  // This y is outside the image.
71  output->Randomize(t, out_iy, ni_, randomizer_);
72  } else {
73  output->CopyTimeStepGeneral(t, out_iy, ni_, input, y_index.t(), 0);
74  }
75  }
76  }
77  }
78  } while (dest_index.Increment());
79  if (debug) DisplayForward(*output);
80 }
TRand * randomizer_
Definition: network.h:311
void DisplayForward(const NetworkIO &matrix)
Definition: network.cpp:282

◆ Serialize()

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

Reimplemented from tesseract::Network.

Definition at line 34 of file convolve.cpp.

34  {
35  return Network::Serialize(fp) &&
36  fp->Serialize(&half_x_) &&
37  fp->Serialize(&half_y_);
38 }
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:151

◆ spec()

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

Reimplemented from tesseract::Network.

Definition at line 40 of file convolve.h.

40  {
41  STRING spec;
42  spec.add_str_int("C", half_x_ * 2 + 1);
43  spec.add_str_int(",", half_y_ * 2 + 1);
44  return spec;
45  }
STRING spec() const override
Definition: convolve.h:40
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
Definition: strngs.h:45

Member Data Documentation

◆ half_x_

int32_t tesseract::Convolve::half_x_
protected

Definition at line 66 of file convolve.h.

◆ half_y_

int32_t tesseract::Convolve::half_y_
protected

Definition at line 67 of file convolve.h.


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