tesseract  4.0.0-1-g2a2b
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 ()=default
 
STRING spec () 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::Reconfig
 Reconfig (const STRING &name, int ni, int x_scale, int y_scale)
 
virtual ~Reconfig ()=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 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 (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 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)
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::Network
static Network * CreateFromFile (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_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_
 
ScrollView * forward_win_
 
ScrollView * backward_win_
 
TRand * randomizer_
 
- 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 }
NetworkType type_
Definition: network.h:299
const STRING & name() const
Definition: network.h:138
Reconfig(const STRING &name, int ni, int x_scale, int y_scale)
Definition: reconfig.cpp:24

◆ ~Maxpool()

virtual tesseract::Maxpool::~Maxpool ( )
virtualdefault

Member Function Documentation

◆ Backward()

bool tesseract::Maxpool::Backward ( bool  debug,
const NetworkIO &  fwd_deltas,
NetworkScratch *  scratch,
NetworkIO *  back_deltas 
)
overridevirtual

Reimplemented from tesseract::Network.

Definition at line 73 of file maxpool.cpp.

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

◆ DeSerialize()

bool tesseract::Maxpool::DeSerialize ( TFile *  fp)
overridevirtual

Reimplemented from tesseract::Network.

Definition at line 31 of file maxpool.cpp.

31  {
32  bool result = Reconfig::DeSerialize(fp);
33  no_ = ni_;
34  return result;
35 }
bool DeSerialize(TFile *fp) override
Definition: reconfig.cpp:58

◆ Forward()

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

Reimplemented from tesseract::Network.

Definition at line 39 of file maxpool.cpp.

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

◆ spec()

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

Reimplemented from tesseract::Network.

Definition at line 35 of file maxpool.h.

35  {
36  STRING spec;
37  spec.add_str_int("Mp", y_scale_);
39  return spec;
40  }
int32_t y_scale_
Definition: reconfig.h:79
int32_t x_scale_
Definition: reconfig.h:78
STRING spec() const override
Definition: maxpool.h:35
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
Definition: strngs.h:45

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