}
/**
+ * @brief return the data type of the tensor
+ * @param tensor_idx : the index of the tensor
+ * @param[out] type : the data type of the input tensor
+ * @return 0 if OK. non-zero if error.
+ */
+int
+TFLiteCore::getTensorType (int tensor_idx, tensor_type * type)
+{
+ switch (interpreter->tensor (tensor_idx)->type) {
+ case kTfLiteFloat32:
+ *type = _NNS_FLOAT32;
+ break;
+ case kTfLiteUInt8:
+ *type = _NNS_UINT8;
+ break;
+ case kTfLiteInt32:
+ *type = _NNS_INT32;
+ break;
+ case kTfLiteBool:
+ *type = _NNS_INT8;
+ break;
+ case kTfLiteInt64:
+ case kTfLiteString:
+ default:
+ *type = _NNS_END;
+ return -1;
+ break;
+ }
+ return 0;
+}
+
+/**
* @brief return the Dimension of Input Tensor.
* @param idx : the index of the input tensor
* @param[out] dim : the array of the input tensor
- * @param[out] len : the length of the input tensor array
+ * @param[out] type : the data type of the input tensor
* @return 0 if OK. non-zero if error.
*/
int
-TFLiteCore::getInputTensorDim (int idx, int **dim, int *len)
+TFLiteCore::getInputTensorDim (int idx, tensor_dim dim, tensor_type * type)
{
if (idx >= input_size) {
return -1;
}
- *dim = interpreter->tensor (input_idx_list[idx])->dims->data;
- *len = interpreter->tensor (input_idx_list[idx])->dims->size;
+ if (getTensorType (input_idx_list[idx], type)) {
+ return -2;
+ }
+ int len = interpreter->tensor (input_idx_list[idx])->dims->size;
+ g_assert (len <= NNS_TENSOR_RANK_LIMIT);
+ memcpy (dim, interpreter->tensor (input_idx_list[idx])->dims->data,
+ sizeof (tensor_dim) / NNS_TENSOR_RANK_LIMIT * len);
+ for (int i = len; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ dim[i] = 1;
+ }
return 0;
}
* @brief return the Dimension of Output Tensor.
* @param idx : the index of the output tensor
* @param[out] dim : the array of the output tensor
- * @param[out] len : the length of the output tensor array
+ * @param[out] type : the data type of the output tensor
* @return 0 if OK. non-zero if error.
*/
int
-TFLiteCore::getOutputTensorDim (int idx, int **dim, int *len)
+TFLiteCore::getOutputTensorDim (int idx, tensor_dim dim, tensor_type * type)
{
if (idx >= output_size) {
return -1;
}
- *dim = interpreter->tensor (output_idx_list[idx])->dims->data;
- *len = interpreter->tensor (output_idx_list[idx])->dims->size;
+ if (getTensorType (output_idx_list[idx], type)) {
+ return -2;
+ }
+ int len = interpreter->tensor (output_idx_list[idx])->dims->size;
+ g_assert (len <= NNS_TENSOR_RANK_LIMIT);
+ memcpy (dim, interpreter->tensor (output_idx_list[idx])->dims->data,
+ sizeof (tensor_dim) / NNS_TENSOR_RANK_LIMIT * len);
+ for (int i = len; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ dim[i] = 1;
+ }
return 0;
}
{
int output_number_of_pixels = 1;
- int sizeOfArray = 0;
- int *inputTensorDim;
- int ret = getInputTensorDim (0, &inputTensorDim, &sizeOfArray);
+ int sizeOfArray = NNS_TENSOR_RANK_LIMIT;
+ tensor_type type;
+ tensor_dim inputTensorDim;
+ int ret = getInputTensorDim (0, inputTensorDim, &type);
if (ret) {
return -1;
}
* @param tflite : the class object
* @param idx : the index of the input tensor
* @param[out] dim : the array of the input tensor
- * @param[out] len : the length of the input tensor array
+ * @param[out] type : the data type of the input tensor
* @return 0 if OK. non-zero if error.
*/
int
-tflite_core_getInputDim (void *tflite, int idx, int **dim, int *len)
+tflite_core_getInputDim (void *tflite, int idx, tensor_dim dim,
+ tensor_type * type)
{
TFLiteCore *c = (TFLiteCore *) tflite;
- return c->getInputTensorDim (idx, dim, len);
+ return c->getInputTensorDim (idx, dim, type);
}
/**
* @param tflite : the class object
* @param idx : the index of the output tensor
* @param[out] dim : the array of the output tensor
- * @param[out] len : the length of the output tensor array
+ * @param[out] type : the data type of the output tensor
* @return 0 if OK. non-zero if error.
*/
int
-tflite_core_getOutputDim (void *tflite, int idx, int **dim, int *len)
+tflite_core_getOutputDim (void *tflite, int idx, tensor_dim dim,
+ tensor_type * type)
{
TFLiteCore *c = (TFLiteCore *) tflite;
- return c->getOutputTensorDim (idx, dim, len);
+ return c->getOutputTensorDim (idx, dim, type);
}
/**
#ifdef __cplusplus
#include <iostream>
+#include <stdint.h>
+#include <glib.h>
+#include "tensor_typedef.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/optional_debug_tools.h"
int getInputTensorSize ();
int getOutputTensorSize ();
- int getInputTensorDim (int idx, int **dim, int *len);
- int getOutputTensorDim (int idx, int **dim, int *len);
+ int getInputTensorDim (int idx, tensor_dim dim, tensor_type * type);
+ int getOutputTensorDim (int idx, tensor_dim dim, tensor_type * type);
int getInputTensorDimSize ();
int getOutputTensorDimSize ();
int invoke (uint8_t * inptr, uint8_t ** outptr);
int output_idx_list_len;
std::unique_ptr < tflite::Interpreter > interpreter;
std::unique_ptr < tflite::FlatBufferModel > model;
+ int getTensorType(int tensor_idx, tensor_type *type);
};
/**
extern void *tflite_core_new (const char *_model_path);
extern void tflite_core_delete (void *tflite);
extern const char *tflite_core_getModelPath (void *tflite);
- extern int tflite_core_getInputDim (void *tflite, int idx, int **dim,
- int *len);
- extern int tflite_core_getOutputDim (void *tflite, int idx, int **dim,
- int *len);
+ extern int tflite_core_getInputDim (void *tflite, int idx, tensor_dim dim,
+ tensor_type * type);
+ extern int tflite_core_getOutputDim (void *tflite, int idx, tensor_dim dim,
+ tensor_type * type);
extern int tflite_core_getInputSize (void *tflite);
extern int tflite_core_getOutputSize (void *tflite);
extern int tflite_core_invoke (void *tflite, uint8_t * inptr,