tesseract  5.0.0-alpha-619-ge9db
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)
 
 ~Maxpool () override=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)
 
 ~Reconfig () override=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 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 void CacheXScaleFactor (int factor)
 
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 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_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_
 
ScrollViewforward_win_
 
ScrollViewbackward_win_
 
TRandrandomizer_
 

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 22 of file maxpool.cpp.

23  : Reconfig(name, ni, x_scale, y_scale) {
24  type_ = NT_MAXPOOL;
25  no_ = ni;
26 }

◆ ~Maxpool()

tesseract::Maxpool::~Maxpool ( )
overridedefault

Member Function Documentation

◆ Backward()

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

Implements tesseract::Network.

Definition at line 71 of file maxpool.cpp.

73  {
74  back_deltas->ResizeToMap(fwd_deltas.int_mode(), back_map_, ni_);
75  back_deltas->MaxpoolBackward(fwd_deltas, maxes_);
76  return true;
77 }

◆ DeSerialize()

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

Implements tesseract::Network.

Definition at line 29 of file maxpool.cpp.

29  {
30  bool result = Reconfig::DeSerialize(fp);
31  no_ = ni_;
32  return result;
33 }

◆ Forward()

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

Implements tesseract::Network.

Definition at line 37 of file maxpool.cpp.

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

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

The documentation for this class was generated from the following files:
STRING::add_str_int
void add_str_int(const char *str, int number)
Definition: strngs.cpp:370
tesseract::Reconfig::DeSerialize
bool DeSerialize(TFile *fp) override
Definition: reconfig.cpp:57
STRING
Definition: strngs.h:45
tesseract::Reconfig::Reconfig
Reconfig(const STRING &name, int ni, int x_scale, int y_scale)
Definition: reconfig.cpp:23
tesseract::Reconfig::y_scale_
int32_t y_scale_
Definition: reconfig.h:83
tesseract::Network::type_
NetworkType type_
Definition: network.h:293
tesseract::Maxpool::spec
STRING spec() const override
Definition: maxpool.h:35
tesseract::FD_WIDTH
Definition: stridemap.h:35
GENERIC_2D_ARRAY::ResizeNoInit
void ResizeNoInit(int size1, int size2, int pad=0)
Definition: matrix.h:90
tesseract::Reconfig::x_scale_
int32_t x_scale_
Definition: reconfig.h:82
tesseract::Network::name
const STRING & name() const
Definition: network.h:138
tesseract::FD_HEIGHT
Definition: stridemap.h:34
tesseract::Reconfig::back_map_
StrideMap back_map_
Definition: reconfig.h:80
tesseract::FD_BATCH
Definition: stridemap.h:33
tesseract::Network::no_
int32_t no_
Definition: network.h:298
tesseract::Network::ni_
int32_t ni_
Definition: network.h:297
tesseract::NT_MAXPOOL
Definition: network.h:48