tesseract  4.00.00dev
tesseract::Maxpool Class Reference

#include <maxpool.h>

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

Public Member Functions

 Maxpool (const STRING &name, int ni, int x_scale, int y_scale)
 
virtual ~Maxpool ()
 
virtual STRING spec () 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::Reconfig
 Reconfig (const STRING &name, int ni, int x_scale, int y_scale)
 
virtual ~Reconfig ()
 
virtual StaticShape OutputShape (const StaticShape &input_shape) const
 
virtual int XScaleFactor () const
 
virtual bool Serialize (TFile *fp) const
 
- 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
 
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 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)
 

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)
 
- Protected Attributes inherited from tesseract::Reconfig
StrideMap back_map_
 
inT32 x_scale_
 
inT32 y_scale_
 
- 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_
 
- Static Protected Attributes inherited from tesseract::Network
static char const *const kTypeNames [NT_COUNT]
 

Detailed Description

Definition at line 29 of file maxpool.h.

Constructor & Destructor Documentation

◆ Maxpool()

tesseract::Maxpool::Maxpool ( const STRING name,
int  ni,
int  x_scale,
int  y_scale 
)

Definition at line 24 of file maxpool.cpp.

25  : Reconfig(name, ni, x_scale, y_scale) {
26  type_ = NT_MAXPOOL;
27  no_ = ni;
28 }
Reconfig(const STRING &name, int ni, int x_scale, int y_scale)
Definition: reconfig.cpp:24
NetworkType type_
Definition: network.h:285

◆ ~Maxpool()

tesseract::Maxpool::~Maxpool ( )
virtual

Definition at line 30 of file maxpool.cpp.

30  {
31 }

Member Function Documentation

◆ Backward()

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

Reimplemented from tesseract::Reconfig.

Definition at line 76 of file maxpool.cpp.

78  {
79  back_deltas->ResizeToMap(fwd_deltas.int_mode(), back_map_, ni_);
80  back_deltas->MaxpoolBackward(fwd_deltas, maxes_);
81  return true;
82 }
StrideMap back_map_
Definition: reconfig.h:76

◆ DeSerialize()

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

Reimplemented from tesseract::Reconfig.

Definition at line 34 of file maxpool.cpp.

34  {
35  bool result = Reconfig::DeSerialize(fp);
36  no_ = ni_;
37  return result;
38 }
virtual bool DeSerialize(TFile *fp)
Definition: reconfig.cpp:62

◆ Forward()

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

Reimplemented from tesseract::Reconfig.

Definition at line 42 of file maxpool.cpp.

44  {
45  output->ResizeScaled(input, x_scale_, y_scale_, no_);
46  maxes_.ResizeNoInit(output->Width(), ni_);
47  back_map_ = input.stride_map();
48 
49  StrideMap::Index dest_index(output->stride_map());
50  do {
51  int out_t = dest_index.t();
52  StrideMap::Index src_index(input.stride_map(), dest_index.index(FD_BATCH),
53  dest_index.index(FD_HEIGHT) * y_scale_,
54  dest_index.index(FD_WIDTH) * x_scale_);
55  // Find the max input out of x_scale_ groups of y_scale_ inputs.
56  // Do it independently for each input dimension.
57  int* max_line = maxes_[out_t];
58  int in_t = src_index.t();
59  output->CopyTimeStepFrom(out_t, input, in_t);
60  for (int i = 0; i < ni_; ++i) {
61  max_line[i] = in_t;
62  }
63  for (int x = 0; x < x_scale_; ++x) {
64  for (int y = 0; y < y_scale_; ++y) {
65  StrideMap::Index src_xy(src_index);
66  if (src_xy.AddOffset(x, FD_WIDTH) && src_xy.AddOffset(y, FD_HEIGHT)) {
67  output->MaxpoolTimeStep(out_t, input, src_xy.t(), max_line);
68  }
69  }
70  }
71  } while (dest_index.Increment());
72 }
StrideMap back_map_
Definition: reconfig.h:76
void ResizeNoInit(int size1, int size2)
Definition: matrix.h:86

◆ spec()

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

Reimplemented from tesseract::Reconfig.

Definition at line 35 of file maxpool.h.

35  {
36  STRING spec;
37  spec.add_str_int("Mp", y_scale_);
38  spec.add_str_int(",", x_scale_);
39  return spec;
40  }
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
Definition: strngs.h:45
virtual STRING spec() const
Definition: maxpool.h:35

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