ONE - On-device Neural Engine
Loading...
Searching...
No Matches
exo::AvgPool2DConverter Class Reference

Convert loco::AvgPool2D to locoex::TFLAveragePool2D. More...

#include <AvgPool2DConverter.h>

Collaboration diagram for exo::AvgPool2DConverter:

Public Member Functions

const char * name (void) const final
 
bool convert (loco::AvgPool2D *origin) final
 Converts loco::AvgPool2D to locoex::TFLAveragePool2D.
 
- Public Member Functions inherited from exo::CanonicalNodeConverter< loco::AvgPool2D >
bool run (loco::Graph *graph)
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Additional Inherited Members

Detailed Description

Convert loco::AvgPool2D to locoex::TFLAveragePool2D.

Definition at line 30 of file AvgPool2DConverter.h.

Member Function Documentation

◆ convert()

bool exo::AvgPool2DConverter::convert ( loco::AvgPool2D origin)
finalvirtual

Converts loco::AvgPool2D to locoex::TFLAveragePool2D.

How it works: (note: ten->fea means input: tensor, output: feature)

Before: Foo -— FeatureEncode -— AvgPool2D -— FeatureDecode -— Bar ten->ten ten->fea fea->fea fea->ten ten->ten

After: AvgPool2D / Foo – FeatureEncode - FeatureDecode - TFLAvgPool2D - FeatureEncode - FeatureDecode – Bar ten->ten ten->fea fea->ten ten->ten ten->fea fea->ten ten->ten

Note
This method replaces AvgPool2D with "FeatureDecode -- TFLAvgPool2D -- FeatureEncode". Redundant nodes will be removed during transforms.

Implements exo::CanonicalNodeConverter< loco::AvgPool2D >.

Definition at line 45 of file AvgPool2DConverter.cpp.

46{
47 auto *graph = origin->graph();
48
50 auto tfl_average = graph->nodes()->create<locoex::TFLAveragePool2D>();
51 {
52 tfl_average->value(dec);
53
54 // set attributes
55 tfl_average->stride()->w(origin->stride()->horizontal());
56 tfl_average->stride()->h(origin->stride()->vertical());
57
58 tfl_average->filter()->w(origin->window()->horizontal());
59 tfl_average->filter()->h(origin->window()->vertical());
60
61 auto pad = origin->pad();
62 if (pad->bottom() == 0 && pad->top() == 0 && pad->left() == 0 && pad->right() == 0)
63 tfl_average->padding(locoex::Padding::VALID);
64 else
65 // TODO This is necessary, but not sufficient condition. More rigorous check required
66 tfl_average->padding(locoex::Padding::SAME);
67
68 tfl_average->fusedActivationFunction(locoex::FusedActFunc::NONE);
69 }
70 auto enc = make_feature_encode<FeatureLayout::NHWC>(tfl_average);
71
72 // replace canonical node
73 loco::replace(origin).with(enc);
74 origin->ifm(nullptr);
75
76 return true;
77}
Node * ifm(void) const
Definition Nodes.h:349
const Stride< 2 > * stride(void) const
Definition Nodes.h:365
const Padding2D * pad(void) const
Definition Nodes.h:357
const Window< 2 > * window(void) const
Definition Nodes.h:361
Graph * graph(void)
Definition Node.h:70
uint32_t horizontal(void) const
Definition Stride.h:40
uint32_t vertical(void) const
Definition Stride.h:36
void with(Node *into) const
Definition Node.cpp:66
uint32_t horizontal(void) const
Definition Window.h:42
uint32_t vertical(void) const
Definition Window.h:38
AVERAGE_POOL_2D in TensorFlow Lite.
Definition TFLNodes.h:130
loco::Node * value(void) const
Definition TFLNodes.h:137
template loco::FeatureDecode * make_feature_decode< FeatureLayout::NHWC >(loco::Node *input_for_encode)
template loco::FeatureEncode * make_feature_encode< FeatureLayout::NHWC >(loco::Node *input_for_encode)
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82

References loco::Node::graph(), loco::Stride< 2 >::horizontal(), loco::Window< 2 >::horizontal(), loco::AvgPool2D::ifm(), exo::make_feature_decode< FeatureLayout::NHWC >(), exo::make_feature_encode< FeatureLayout::NHWC >(), locoex::NONE, loco::AvgPool2D::pad(), loco::replace(), locoex::SAME, loco::AvgPool2D::stride(), locoex::VALID, locoex::TFLAveragePool2D::value(), loco::Stride< 2 >::vertical(), loco::Window< 2 >::vertical(), loco::AvgPool2D::window(), and loco::Subst< SubstQualifier::Default >::with().

◆ name()

const char * exo::AvgPool2DConverter::name ( void  ) const
inlinefinalvirtual

Reimplemented from exo::CanonicalNodeConverter< loco::AvgPool2D >.

Definition at line 33 of file AvgPool2DConverter.h.

33{ return "exo::AvgPool2DConverter"; }

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