From fe317bea8d631b64b0353152cabc14b32ffb041c Mon Sep 17 00:00:00 2001 From: HyoungjooAhn Date: Fri, 21 Sep 2018 14:25:06 +0900 Subject: [PATCH] [Filter/TF-Lite] remove memcpy for input tensor copy data pointer directly rather than the memcpy logic at input tensor Signed-off-by: HyoungjooAhn --- .../tensor_filter_tensorflow_lite_core.cc | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/gst/tensor_filter/tensor_filter_tensorflow_lite_core.cc b/gst/tensor_filter/tensor_filter_tensorflow_lite_core.cc index 431a9ea..77390c8 100644 --- a/gst/tensor_filter/tensor_filter_tensorflow_lite_core.cc +++ b/gst/tensor_filter/tensor_filter_tensorflow_lite_core.cc @@ -284,13 +284,6 @@ TFLiteCore::invoke (const GstTensorMemory * input, GstTensorMemory * output) gettimeofday (&start_time, nullptr); #endif - int num_of_input[NNS_TENSOR_SIZE_LIMIT]; - for (int i = 0; i < NNS_TENSOR_SIZE_LIMIT; i++) { - num_of_input[i] = 1; - } - - int sizeOfArray = NNS_TENSOR_RANK_LIMIT; - if (interpreter->AllocateTensors () != kTfLiteOk) { printf ("Failed to allocate tensors\n"); return -2; @@ -299,18 +292,35 @@ TFLiteCore::invoke (const GstTensorMemory * input, GstTensorMemory * output) for (int i = 0; i < getInputTensorSize (); i++) { int in_tensor = interpreter->inputs ()[i]; - for (int j = 0; j < sizeOfArray; j++) { - num_of_input[i] *= inputTensorMeta.info[i].dimension[j]; - } - - for (int j = 0; j < num_of_input[i]; j++) { - if (inputTensorMeta.info[i].type == _NNS_FLOAT32) { - (interpreter->typed_tensor < float >(in_tensor))[j] = - ((float *) input[i].data)[j]; - } else if (inputTensorMeta.info[i].type == _NNS_UINT8) { - (interpreter->typed_tensor < uint8_t > (in_tensor))[j] = - ((uint8_t *) input[i].data)[j]; - } + TfLiteTensor *inputTensor = interpreter->tensor (in_tensor); + + switch (inputTensorMeta.info[i].type) { + case _NNS_FLOAT32: + inputTensor->data.f = (float *) input[i].data; + break; + + case _NNS_UINT8: + inputTensor->data.uint8 = (uint8_t *) input[i].data; + break; + + case _NNS_INT32: + inputTensor->data.i32 = (int *) input[i].data; + break; + + case _NNS_INT64: + inputTensor->data.i64 = (int64_t *) input[i].data; + break; + + case _NNS_UINT32: + case _NNS_INT16: + case _NNS_UINT16: + case _NNS_INT8: + case _NNS_FLOAT64: + case _NNS_UINT64: + default: + _print_log ("Not Supported Type"); + return -3; + break; } } -- 2.7.4