From e2d7d94549b7fda2944f1410ccb3892e7757b19a Mon Sep 17 00:00:00 2001 From: Raman Sarokin Date: Wed, 3 Jun 2020 11:27:03 -0700 Subject: [PATCH] Added check for unsupported Mul case. PiperOrigin-RevId: 314569439 Change-Id: I788a87b6ac20cbd3f01d522029d330f9b6057e20 --- .../delegates/gpu/common/model_builder.cc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tensorflow/lite/delegates/gpu/common/model_builder.cc b/tensorflow/lite/delegates/gpu/common/model_builder.cc index 9cb738cf935..adfbacb6d36 100644 --- a/tensorflow/lite/delegates/gpu/common/model_builder.cc +++ b/tensorflow/lite/delegates/gpu/common/model_builder.cc @@ -1143,6 +1143,30 @@ class MulOperationParser : public TFLiteOperationParser { if (tflite_node->inputs->size != 2) { return absl::UnimplementedError("MUL requires two input tensors."); } + auto input0 = tflite::GetInput(context, tflite_node, 0); + auto input1 = tflite::GetInput(context, tflite_node, 1); + if (input0->dims->size == input1->dims->size) { + // this code checks that at least one input of Mul not smaller in all + // dimensions. Sometimes Mul used for matrix-vector multiplication that we + // currently don't support. For example input0 HWC(1, 256, 1), input1 + // HWC(1, 1, 256) -> output HWC (1, 256, 256). In this case it can be + // replaced with Convolution operation. + bool first_has_smaller_dim = false; + bool second_has_smaller_dim = false; + for (int i = 0; i < input0->dims->size; ++i) { + if (input0->dims->data[i] < input1->dims->data[i]) { + first_has_smaller_dim = true; + } + if (input1->dims->data[i] < input0->dims->data[i]) { + second_has_smaller_dim = true; + } + } + if (first_has_smaller_dim && second_has_smaller_dim) { + return absl::UnimplementedError( + "MUL requires one tensor that not less than second in all " + "dimensions."); + } + } const TfLiteMulParams* tf_options; RETURN_IF_ERROR(RetrieveBuiltinData(tflite_node, &tf_options)); return IsActivationSupported(tf_options->activation);