ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tflchef::TFliteOpOneHot Class Reference

tflchef operator builder for OneHot More...

#include <OneHot.h>

Collaboration diagram for tflchef::TFliteOpOneHot:

Public Member Functions

void filler (const tflite::Operator *op, TFliteImport *import, tflchef::ModelRecipe *model_recipe) const override
 
tflchef::Operation * build (RecipeChefContext *ctx) const override
 
- Public Member Functions inherited from tflchef::TFliteOpChef
virtual ~TFliteOpChef ()
 

Detailed Description

tflchef operator builder for OneHot

Definition at line 28 of file OneHot.h.

Member Function Documentation

◆ build()

tflchef::Operation * tflchef::TFliteOpOneHot::build ( RecipeChefContext ctx) const
overridevirtual

Implements tflchef::TFliteOpChef.

Definition at line 70 of file OneHot.cpp.

71{
72 tflchef::Operation *operation = ctx->chefop;
73 const tflite::Operator *op = ctx->tflop;
74
75 auto op_params = op->builtin_options_as_OneHotOptions();
76 assert(op_params != nullptr);
77
78 operation->set_type("OneHot");
79
80 auto op_options = operation->mutable_onehot_options();
81
82 op_options->set_axis(op_params->axis());
83
84 return operation;
85}

References tflchef::RecipeChefContext::chefop, and tflchef::RecipeChefContext::tflop.

◆ filler()

void tflchef::TFliteOpOneHot::filler ( const tflite::Operator *  op,
TFliteImport import,
tflchef::ModelRecipe *  model_recipe 
) const
overridevirtual

Implements tflchef::TFliteOpChef.

Definition at line 23 of file OneHot.cpp.

25{
26 // only depth(second input) has constant on recipe cause depth value is used in shape inference.
27 const auto &inputs = *op->inputs();
28
29 const tflite::Tensor *tensor = import->tensors()->Get(inputs[1]);
30 assert(tensor->type() == tflite::TensorType::TensorType_INT32);
31 const tflite::Buffer *buffer = import->buffers()->Get(tensor->buffer());
32
33 if (buffer && buffer->data())
34 {
35 auto vec = extract_buffer<int32_t>(buffer);
36 import->set_tensor_filler(inputs[1], vec);
37 }
38
39 // on/off can be dtype of input/output. let's support INT32/FLOAT32 for now
40 for (int32_t index = 2; index <= 3; ++index)
41 {
42 const tflite::Tensor *tensor = import->tensors()->Get(inputs[index]);
43 const tflite::Buffer *buffer = import->buffers()->Get(tensor->buffer());
44 if (buffer && buffer->data())
45 {
46 switch (tensor->type())
47 {
48 case tflite::TensorType::TensorType_INT32:
49 {
50 auto vec = extract_buffer<int32_t>(buffer);
51 import->set_tensor_filler(inputs[index], vec);
52 break;
53 }
54
55 case tflite::TensorType::TensorType_FLOAT32:
56 {
57 auto vec = extract_buffer<float>(buffer);
58 import->set_tensor_filler(inputs[index], vec);
59 break;
60 }
61
62 default:
63 assert(false);
64 break;
65 }
66 }
67 }
68}
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

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