ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mir::ops::ResizeOp Class Reference

Resize operation scales are such that output = input * scale for each dimension and the number of dimensions matches. More...

#include <ResizeOp.h>

Collaboration diagram for mir::ops::ResizeOp:

Public Types

enum class  ResizeMethod { nearestNeighbor }
 
- Public Types inherited from mir::Operation
enum class  Type { HANDLE_OP }
 

Public Member Functions

 ResizeOp (Output *arg, ResizeMethod mode, const std::vector< float > &scales)
 
OperationcopyWithInputs (const std::vector< Output * > &inputs) override
 
 ResizeOp (Output *arg, ResizeMethod mode, const Shape &output_shape)
 
ResizeMethod getMode () const
 
const std::vector< float > & getScales () const
 
- Public Member Functions inherited from mir::Operation
virtual ~Operation ()=default
 
Type getType () const
 
std::size_t getId () const
 
void setId (std::size_t id)
 
std::size_t getNumInputs () const
 
std::size_t getNumOutputs () const
 
std::deque< Output * > & getInputs ()
 
const std::deque< Output * > & getInputs () const
 
std::deque< Output > & getOutputs ()
 
const std::deque< Output > & getOutputs () const
 
OutputgetInput (std::size_t index)
 
const OutputgetInput (std::size_t index) const
 
OutputgetOutput (std::size_t index)
 
const OutputgetOutput (std::size_t index) const
 
const ShapegetInputShape (std::size_t index) const
 
const ShapegetOutputShape (std::size_t index) const
 
void accept (IVisitor *v)
 

Additional Inherited Members

- Protected Member Functions inherited from mir::Operation
 Operation (Type type, const std::vector< Output * > &inputs, std::size_t num_outputs=1)
 
void setOutputType (std::size_t index, const TensorType &type)
 

Detailed Description

Resize operation scales are such that output = input * scale for each dimension and the number of dimensions matches.

Definition at line 34 of file ResizeOp.h.

Member Enumeration Documentation

◆ ResizeMethod

Enumerator
nearestNeighbor 

Definition at line 37 of file ResizeOp.h.

38 {
39 nearestNeighbor, // TODO: BICUBIC and BILINEAR
40 };

Constructor & Destructor Documentation

◆ ResizeOp() [1/2]

mir::ops::ResizeOp::ResizeOp ( Output arg,
ResizeMethod  mode,
const std::vector< float > &  scales 
)
inline

Definition at line 42 of file ResizeOp.h.

43 : Operation(Type::resizeIm, {arg}), _mode(mode), _scales(scales)
44 {
45 // Infer output shape based on given scales.
46 auto &input_shape = getInputShape(0);
47 assert(input_shape.rank() == 4 && _scales.size() == 4);
48 Shape output_shape(input_shape.rank());
49
50 for (int32_t i = 0; i < input_shape.rank(); ++i)
51 {
52 output_shape.dim(i) = static_cast<int32_t>(lroundf(_scales.at(i) * input_shape.dim(i)));
53 }
54
56 }
DataType getElementType() const
Definition Operation.h:98
Output * getInput(std::size_t index)
Definition Operation.h:137
const Shape & getInputShape(std::size_t index) const
Definition Operation.h:161
void setOutputType(std::size_t index, const TensorType &type)
Definition Operation.h:172
const luci_interpreter::RuntimeShape output_shape
Definition Shape.h:28

◆ ResizeOp() [2/2]

mir::ops::ResizeOp::ResizeOp ( Output arg,
ResizeMethod  mode,
const Shape output_shape 
)
inline

Definition at line 63 of file ResizeOp.h.

64 : Operation(Type::resizeIm, {arg}), _mode(mode)
65 {
66 // Calculate scales based on given shape.
67 auto &input_shape = getInputShape(0);
68 assert(input_shape.rank() == 4 && output_shape.rank() == 4);
70 _scales = {1.0f, static_cast<float>(output_shape.dim(1)) / input_shape.dim(1),
71 static_cast<float>(output_shape.dim(2)) / input_shape.dim(2), 1.0f};
72 }

Member Function Documentation

◆ copyWithInputs()

Operation * mir::ops::ResizeOp::copyWithInputs ( const std::vector< Output * > &  inputs)
inlineoverridevirtual

Implements mir::Operation.

Definition at line 58 of file ResizeOp.h.

59 {
60 return new ResizeOp(inputs[0], _mode, getOutputShape(0));
61 }
const Shape & getOutputShape(std::size_t index) const
Definition Operation.h:163
ResizeOp(Output *arg, ResizeMethod mode, const std::vector< float > &scales)
Definition ResizeOp.h:42

References mir::Operation::getOutputShape().

◆ getMode()

ResizeMethod mir::ops::ResizeOp::getMode ( ) const
inline
Returns
The resize mode

Definition at line 75 of file ResizeOp.h.

75{ return _mode; }

Referenced by mir_interpreter::MIRInterpreter::visit(), nnc::ModelAnalyzer::visit(), and mir::DotNodeBuilder::visit().

◆ getScales()

const std::vector< float > & mir::ops::ResizeOp::getScales ( ) const
inline

Definition at line 77 of file ResizeOp.h.

77{ return _scales; }

Referenced by mir_interpreter::MIRInterpreter::visit().


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