77 : _ifm_name{model.ifm_name()}, _ofm_name{model.ofm_name()}
86 const auto &ker_shape = model.ker_shape();
88 _kernel.resize(num_elements(ker_shape));
90 auto kernel_overlay = make_overlay<float, NHWCLayout>(ker_shape, _kernel.data());
92 for (uint32_t n = 0; n < ker_shape.count(); ++n)
94 for (uint32_t ch = 0; ch < ker_shape.depth(); ++ch)
96 for (uint32_t row = 0; row < ker_shape.height(); ++row)
98 for (uint32_t col = 0; col < ker_shape.width(); ++col)
100 kernel_overlay.at(n, ch, row, col) = model.ker_data().at(n, ch, row, col);
107 _bias.resize(ker_shape.count(), 0.0f);
110 auto quantization = make_default_quantization();
117 _interp.AddTensors(4);
119 _interp.SetTensorParametersReadWrite(0, kTfLiteFloat32 , _ofm_name.c_str(),
120 as_dims(model.ofm_shape()), quantization);
122 _interp.SetTensorParametersReadWrite(1, kTfLiteFloat32 , _ifm_name.c_str(),
123 as_dims(model.ifm_shape()), quantization);
125 _interp.SetTensorParametersReadOnly(
126 2, kTfLiteFloat32 ,
"kernel" , as_dims(model.ker_shape()), quantization,
127 reinterpret_cast<const char *
>(_kernel.data()), _kernel.size() *
sizeof(
float));
129 _interp.SetTensorParametersReadOnly(
130 3, kTfLiteFloat32 ,
"bias" , {
static_cast<int>(_bias.size())}, quantization,
131 reinterpret_cast<const char *
>(_bias.data()), _bias.size() *
sizeof(float));
133 auto param = typed_malloc<TfLiteConvParams>();
135 param->padding = kTfLitePaddingValid;
136 param->stride_width = 1;
137 param->stride_height = 1;
138 param->activation = kTfLiteActNone;
140 _interp.AddNodeWithParameters({1, 2, 3}, {0},
nullptr, 0,
reinterpret_cast<void *
>(param),
141 BuiltinOpResolver().FindOp(BuiltinOperator_CONV_2D));
143 _interp.SetInputs({1});
144 _interp.SetOutputs({0});