Update other builders for hexagon delegate to use the method to compute and add
min/max to the op. PiperOrigin-RevId: 323644369 Change-Id: I96cfe9cb506662111c7545194f998306b2b293fd
This commit is contained in:
parent
3a70eef32d
commit
5f8e3e8d54
@ -41,7 +41,6 @@ class ActivationOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
float relu_value_ = 6;
|
||||
};
|
||||
|
||||
|
||||
@ -36,7 +36,6 @@ class ArgMinMaxOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -33,29 +33,15 @@ TfLiteStatus ArithmeticOpBuilder::PopulateSubGraph(
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input1_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input1_tensor, &input1_min_, &input1_max_));
|
||||
auto* input1_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input1_min_), sizeof(input1_min_));
|
||||
auto* input1_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input1_max_), sizeof(input1_max_));
|
||||
|
||||
// Second input data tensor.
|
||||
tensor_id = inputs->data[1];
|
||||
const auto& input2_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input2_tensor, &input2_min_, &input2_max_));
|
||||
auto* input2_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input2_min_), sizeof(input2_min_));
|
||||
auto* input2_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input2_max_), sizeof(input2_max_));
|
||||
|
||||
// Min/max values for input tensors.
|
||||
AddInput(TensorID(input1_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input1_max_const->GetID(), 0));
|
||||
AddInput(TensorID(input2_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input2_max_const->GetID(), 0));
|
||||
// Inputs min/max
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input1_tensor));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input2_tensor));
|
||||
|
||||
// Output details.
|
||||
TF_LITE_ENSURE_STATUS(ComputeMinAndMaxQuantValues(
|
||||
|
||||
@ -38,8 +38,7 @@ class ArithmeticOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input1_min_, input1_max_, input2_min_, input2_max_, output_min_,
|
||||
output_max_;
|
||||
float output_min_, output_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -31,24 +31,11 @@ TfLiteStatus HardSwishOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input1_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input1_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input1_tensor));
|
||||
|
||||
// Output min/max
|
||||
TF_LITE_ENSURE_STATUS(ComputeMinAndMaxQuantValues(
|
||||
context->tensors[outputs->data[0]], &output_min_, &output_max_));
|
||||
auto* output_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_min_), sizeof(output_min_));
|
||||
auto* output_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_max_), sizeof(output_max_));
|
||||
AddInput(TensorID(output_min_const->GetID(), 0));
|
||||
AddInput(TensorID(output_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeAndAddMinAndMax(context, context->tensors[outputs->data[0]]));
|
||||
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
output_depth_size;
|
||||
|
||||
@ -40,7 +40,6 @@ class HardSwishOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_, output_min_, output_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -32,14 +32,7 @@ TfLiteStatus L2NormalizationOpBuilder::PopulateSubGraph(
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -38,7 +38,6 @@ class L2NormalizationOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -35,40 +35,13 @@ TfLiteStatus MinMaxOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
AddInput(graph_builder_->GetHexagonTensorId(b_tensor_id));
|
||||
|
||||
// Add Inputs A & B min/max
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(a_tensor, &a_input_min_, &a_input_max_));
|
||||
auto* a_input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&a_input_min_),
|
||||
sizeof(a_input_min_));
|
||||
auto* a_input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&a_input_max_),
|
||||
sizeof(a_input_max_));
|
||||
AddInput(TensorID(a_input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(a_input_max_const->GetID(), 0));
|
||||
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(b_tensor, &b_input_min_, &b_input_max_));
|
||||
auto* b_input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&b_input_min_),
|
||||
sizeof(b_input_min_));
|
||||
auto* b_input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&b_input_max_),
|
||||
sizeof(b_input_max_));
|
||||
AddInput(TensorID(b_input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(b_input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, a_tensor));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, b_tensor));
|
||||
|
||||
// Add output min/max
|
||||
const int output_tensor_id = outputs->data[0];
|
||||
const auto& output_tensor = context->tensors[output_tensor_id];
|
||||
float output_min, output_max;
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(output_tensor, &output_min, &output_max));
|
||||
auto* output_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_min), sizeof(output_min));
|
||||
auto* output_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_max), sizeof(output_max));
|
||||
AddInput(TensorID(output_min_const->GetID(), 0));
|
||||
AddInput(TensorID(output_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, output_tensor));
|
||||
|
||||
// Add outputs.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -35,7 +35,6 @@ class MinMaxOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float a_input_min_, a_input_max_, b_input_min_, b_input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -65,14 +65,7 @@ TfLiteStatus MirrorPadOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
}
|
||||
|
||||
// Min/max values for input tensor.
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -38,7 +38,6 @@ class MirrorPadOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
std::vector<int> paddings_shape_;
|
||||
};
|
||||
|
||||
|
||||
@ -26,13 +26,7 @@ TfLiteStatus NegOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_);
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -34,7 +34,6 @@ class NegOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -32,16 +32,9 @@ TfLiteStatus PadOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
|
||||
// Min/max values for input tensor.
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Padding tensor.
|
||||
tensor_id = inputs->data[1];
|
||||
|
||||
@ -38,7 +38,6 @@ class PadOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -33,14 +33,7 @@ TfLiteStatus Pool2dOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& data_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(data_tensor, &data_min_, &data_max_));
|
||||
auto* data_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, (char*)&data_min_, sizeof(data_min_));
|
||||
auto* data_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, (char*)&data_max_, sizeof(data_max_));
|
||||
AddInput(TensorID(data_min_const->GetID(), 0));
|
||||
AddInput(TensorID(data_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, data_tensor));
|
||||
|
||||
const TfLitePoolParams* pool_params =
|
||||
reinterpret_cast<const TfLitePoolParams*>(builtin_data_);
|
||||
|
||||
@ -40,7 +40,7 @@ class Pool2dOpBuilder : public OpBuilder {
|
||||
TensorID node_output_;
|
||||
std::vector<int> stride_shape_;
|
||||
std::vector<int> filter_shape_;
|
||||
float data_min_, data_max_, output_min_, output_max_;
|
||||
float output_min_, output_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -28,36 +28,16 @@ namespace hexagon {
|
||||
TfLiteStatus QuantizeOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
const TfLiteIntArray* outputs,
|
||||
TfLiteContext* context) {
|
||||
// Input.
|
||||
float input_min = 0;
|
||||
float input_max = 0;
|
||||
const auto& input_tensor = context->tensors[inputs->data[0]];
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min, &input_max);
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min), sizeof(input_min));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max), sizeof(input_max));
|
||||
|
||||
// Output.
|
||||
float output_min = 0;
|
||||
float output_max = 0;
|
||||
const auto& output_tensor = context->tensors[outputs->data[0]];
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(output_tensor, &output_min, &output_max));
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
output_depth_size;
|
||||
GetDims(&output_batch_size, &output_height_size, &output_width_size,
|
||||
&output_depth_size, output_tensor.dims);
|
||||
auto* requantized_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_min), sizeof(output_min));
|
||||
auto* requantized_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_max), sizeof(output_max));
|
||||
|
||||
AddInput(graph_builder_->GetHexagonTensorId(inputs->data[0]));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
AddInput(TensorID(requantized_min_const->GetID(), 0));
|
||||
AddInput(TensorID(requantized_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, output_tensor));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
node_output_ = AddOutput(sizeof(uint8_t), 4,
|
||||
|
||||
@ -33,15 +33,7 @@ TfLiteStatus ReduceOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_);
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
|
||||
// Min/max values for input tensor.
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Axes tensor should be constant.
|
||||
tensor_id = inputs->data[1];
|
||||
|
||||
@ -38,7 +38,6 @@ class ReduceOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -47,15 +47,8 @@ TfLiteStatus ResizeBilinearOpBuilder::PopulateSubGraph(
|
||||
AddInput(TensorID(dims_const->GetID(), 0));
|
||||
|
||||
// Input min/max
|
||||
TF_LITE_ENSURE_OK(context, ComputeMinAndMaxQuantValues(
|
||||
input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
// Align Corners & half-pixel-centers.
|
||||
const TfLiteResizeBilinearParams* params =
|
||||
reinterpret_cast<const TfLiteResizeBilinearParams*>(builtin_data_);
|
||||
|
||||
@ -36,7 +36,6 @@ class ResizeBilinearOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -32,12 +32,6 @@ TfLiteStatus ResizeNearestNeighborOpBuilder::PopulateSubGraph(
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
|
||||
// Output dimensions tensor.
|
||||
tensor_id = inputs->data[1];
|
||||
@ -53,8 +47,7 @@ TfLiteStatus ResizeNearestNeighborOpBuilder::PopulateSubGraph(
|
||||
}
|
||||
|
||||
// Min/max values for input tensor.
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Align corners.
|
||||
const TfLiteResizeNearestNeighborParams* params =
|
||||
|
||||
@ -39,7 +39,6 @@ class ResizeNearestNeighborOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -64,14 +64,7 @@ TfLiteStatus SliceOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
AddInput(TensorID(sizes_node->GetID(), 0));
|
||||
|
||||
// Input min/max
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Outputs
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -35,7 +35,6 @@ class SliceOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -33,14 +33,7 @@ TfLiteStatus SoftmaxOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, (char*)&input_min_, sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, (char*)&input_max_, sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// beta value
|
||||
const TfLiteSoftmaxParams* softmax_params =
|
||||
|
||||
@ -39,7 +39,6 @@ class SoftmaxOpBuilder : public OpBuilder {
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float beta_value_ = 1.0f;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -30,13 +30,6 @@ TfLiteStatus SpaceToDepthOpBuilder::PopulateSubGraph(
|
||||
TfLiteContext* context) {
|
||||
// Input tensor.
|
||||
int tensor_id = inputs->data[0];
|
||||
const auto& input_tensor = context->tensors[tensor_id];
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
|
||||
// Block size.
|
||||
const TfLiteSpaceToDepthParams* space_to_depth_params =
|
||||
@ -48,8 +41,8 @@ TfLiteStatus SpaceToDepthOpBuilder::PopulateSubGraph(
|
||||
// All inputs.
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
AddInput(TensorID(block_size_node->GetID(), 0));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeAndAddMinAndMax(context, context->tensors[tensor_id]));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -40,7 +40,6 @@ class SpaceToDepthOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
int block_size_;
|
||||
};
|
||||
|
||||
|
||||
@ -53,14 +53,7 @@ TfLiteStatus SplitOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
|
||||
// Input data tensor & min/max.
|
||||
AddInput(graph_builder_->GetHexagonTensorId(input_tensor_id));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Output data tensors.
|
||||
for (int i = 0; i < outputs->size; ++i) {
|
||||
|
||||
@ -38,8 +38,6 @@ class SplitOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
std::vector<TensorID> node_outputs_;
|
||||
float input_min_;
|
||||
float input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -67,14 +67,7 @@ TfLiteStatus StridedSliceOpBuilder::PopulateSubGraph(
|
||||
AddInput(TensorID(shrink_axis_mask_const->GetID(), 0));
|
||||
|
||||
// Input min/max
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Slice outputs.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -35,7 +35,6 @@ class StridedSliceOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
|
||||
} // namespace hexagon
|
||||
|
||||
@ -39,15 +39,7 @@ TfLiteStatus TransposeOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
}
|
||||
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(input_tensor, &input_min_, &input_max_));
|
||||
auto* input_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_min_), sizeof(input_min_));
|
||||
auto* input_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&input_max_), sizeof(input_max_));
|
||||
// Min/max values for input tensor.
|
||||
AddInput(TensorID(input_min_const->GetID(), 0));
|
||||
AddInput(TensorID(input_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
|
||||
|
||||
// Hexagon outputs for this node.
|
||||
int output_batch_size, output_height_size, output_width_size,
|
||||
|
||||
@ -34,7 +34,6 @@ class TransposeOpBuilder : public OpBuilder {
|
||||
|
||||
private:
|
||||
TensorID node_output_;
|
||||
float input_min_, input_max_;
|
||||
};
|
||||
} // namespace hexagon
|
||||
} // namespace delegates
|
||||
|
||||
@ -83,14 +83,6 @@ TfLiteStatus TransposeConv2dOpBuilder::PopulateSubGraph(
|
||||
int tensor_id = inputs->data[2];
|
||||
const auto& data_tensor = context->tensors[tensor_id];
|
||||
AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
|
||||
float data_min = 0;
|
||||
float data_max = 0;
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeMinAndMaxQuantValues(data_tensor, &data_min, &data_max));
|
||||
auto* data_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&data_min), sizeof(data_min));
|
||||
auto* data_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&data_max), sizeof(data_max));
|
||||
|
||||
// WEIGHTS.
|
||||
tensor_id = inputs->data[1];
|
||||
@ -150,8 +142,7 @@ TfLiteStatus TransposeConv2dOpBuilder::PopulateSubGraph(
|
||||
kScalarShape, reinterpret_cast<char*>(&weights_max), sizeof(weights_max));
|
||||
|
||||
// Min/max inputs for data & weights tensors.
|
||||
AddInput(TensorID(data_min_const->GetID(), 0));
|
||||
AddInput(TensorID(data_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, data_tensor));
|
||||
AddInput(TensorID(weights_min_const->GetID(), 0));
|
||||
AddInput(TensorID(weights_max_const->GetID(), 0));
|
||||
|
||||
@ -206,16 +197,8 @@ TfLiteStatus TransposeConv2dOpBuilder::PopulateSubGraph(
|
||||
AddInput(TensorID(bias_max_const->GetID(), 0));
|
||||
|
||||
// Output quantization.
|
||||
float output_min = 0;
|
||||
float output_max = 0;
|
||||
ComputeMinAndMaxQuantValues(context->tensors[outputs->data[0]], &output_min,
|
||||
&output_max);
|
||||
auto* output_min_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_min), sizeof(output_min));
|
||||
auto* output_max_const = graph_builder_->AddConstNodeWithData(
|
||||
kScalarShape, reinterpret_cast<char*>(&output_max), sizeof(output_max));
|
||||
AddInput(TensorID(output_min_const->GetID(), 0));
|
||||
AddInput(TensorID(output_max_const->GetID(), 0));
|
||||
TF_LITE_ENSURE_STATUS(
|
||||
ComputeAndAddMinAndMax(context, context->tensors[outputs->data[0]]));
|
||||
|
||||
// Channel scales, if this op is per-channel quantized.
|
||||
if (channel_scales_node_ != nullptr) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user