tesseract  4.00.00dev
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 ()
 
virtual STRING spec () 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
 
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 flags)
 
virtual int InitWeights (float range, TRand *randomizer)
 
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, 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 half_x_
 
inT32 half_y_
 
- 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 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 }

◆ ~Convolve()

tesseract::Convolve::~Convolve ( )
virtual

Definition at line 33 of file convolve.cpp.

33  {
34 }

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Network.

Definition at line 88 of file convolve.cpp.

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

◆ DeSerialize()

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

Reimplemented from tesseract::Network.

Definition at line 45 of file convolve.cpp.

45  {
46  if (fp->FReadEndian(&half_x_, sizeof(half_x_), 1) != 1) return false;
47  if (fp->FReadEndian(&half_y_, sizeof(half_y_), 1) != 1) return false;
48  no_ = ni_ * (2*half_x_ + 1) * (2*half_y_ + 1);
49  return true;
50 }

◆ Forward()

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

Reimplemented from tesseract::Network.

Definition at line 54 of file convolve.cpp.

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

◆ Serialize()

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

Reimplemented from tesseract::Network.

Definition at line 37 of file convolve.cpp.

37  {
38  if (!Network::Serialize(fp)) return false;
39  if (fp->FWrite(&half_x_, sizeof(half_x_), 1) != 1) return false;
40  if (fp->FWrite(&half_y_, sizeof(half_y_), 1) != 1) return false;
41  return true;
42 }
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:153

◆ spec()

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

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  }
virtual STRING spec() const
Definition: convolve.h:40
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
Definition: strngs.h:45

Member Data Documentation

◆ half_x_

inT32 tesseract::Convolve::half_x_
protected

Definition at line 66 of file convolve.h.

◆ half_y_

inT32 tesseract::Convolve::half_y_
protected

Definition at line 67 of file convolve.h.


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