55 const circle::Tensor *filter,
56 const circle::Tensor *output,
57 const circle::Conv2DOptions *options)
61 if (isSupportedQuantized(input, filter))
64 const auto input_scale =
static_cast<double>(Tensor::scale(input));
65 const auto filter_scale =
static_cast<double>(Tensor::scale(filter));
66 const auto output_scale =
static_cast<double>(Tensor::scale(output));
68 const double real_multiplier = input_scale * filter_scale / output_scale;
69 int32_t output_multiplier{};
73 params.output_multiplier = output_multiplier;
74 params.output_shift = output_shift;
76 int32_t activation_min{};
77 int32_t activation_max{};
79 output, &activation_min, &activation_max);
82 params.input_offset = -Tensor::zero_point(input);
83 params.weights_offset = -Tensor::zero_point(filter);
84 params.output_offset = Tensor::zero_point(output);
85 params.quantized_activation_min = activation_min;
86 params.quantized_activation_max = activation_max;
89 else if (isSupportedQuantizedPerChannel(input, filter))
92 int32_t activation_min{};
93 int32_t activation_max{};
95 output, &activation_min, &activation_max);
98 Tensor::scale(input), Tensor::scales(filter), Tensor::scale(output));
100 size_t n = effective_output_scale.size();
101 params.per_channel_output_shift.resize(n);
102 params.per_channel_output_multiplier.resize(n);
103 for (
size_t i = 0; i < n; ++i)
106 ¶ms.per_channel_output_multiplier[i],
107 ¶ms.per_channel_output_shift[i]);
110 params.input_offset = -Tensor::zero_point(input);
111 params.weights_offset = -Tensor::zero_point(filter);
112 params.output_offset = Tensor::zero_point(output);
113 params.quantized_activation_min = activation_min;
114 params.quantized_activation_max = activation_max;
118 else if (Tensor::element_type(input) == DataType::FLOAT32 and
119 Tensor::element_type(filter) == DataType::FLOAT32)
122 float activation_min{};
123 float activation_max{};
125 &activation_min, &activation_max);
127 params.float_activation_min = activation_min;
128 params.float_activation_max = activation_max;
133 assert(
false &&
"Not supported type");
136 const auto padding = options->padding();
137 const auto stride_height = options->stride_h();
138 const auto stride_width = options->stride_w();
139 const auto dilation_height_factor = options->dilation_h_factor();
140 const auto dilation_width_factor = options->dilation_h_factor();
142 params.padding_values.height =
144 params.padding_values.width =
146 params.stride_height = stride_height;
147 params.stride_width = stride_width;
148 params.dilation_height_factor = dilation_height_factor;
149 params.dilation_width_factor = dilation_width_factor;