return 0;
meta->num_tensors = num;
- meta->dims = g_new (tensor_dim, num);
- meta->types = g_new (tensor_type, num);
- meta->ranks = (unsigned int *) g_malloc (sizeof (gint) * num);
if (gst_structure_get_int (str, "rank", (int *) &rank)) {
if (rank != NNS_TENSOR_RANK_LIMIT) {
}
}
if (0 == rank)
- goto err_alloc;
+ return 0;
if (gst_structure_get_fraction (str, "framerate", &fn, &fd)) {
if (framerate_num)
if (counter >= num) {
err_print
("The number of dimensions does not match the number of tensors.\n");
- goto err_alloc;
+ return 0;
}
ret = get_tensor_dimension (ftrim (strv[counter]), meta->dims[counter]);
if (ret > NNS_TENSOR_RANK_LIMIT || ret < 1)
- goto err_alloc;
+ return 0;
counter++;
}
if (counter != num) {
err_print
("The number of dimensions does not match the number of tensors.\n");
- goto err_alloc;
+ return 0;
}
g_strfreev (strv);
while (strv[counter]) {
if (counter >= num) {
err_print ("The number of types does not match the number of tensors.\n");
- goto err_alloc;
+ return 0;
}
meta->types[counter] = get_tensor_type (ftrim (strv[counter]));
if (meta->types[counter] >= _NNS_END)
- goto err_alloc;
+ return 0;
counter++;
}
if (counter != num) {
err_print ("The number of types does not match the number of tensors.\n");
- goto err_alloc;
+ return 0;
}
g_strfreev (strv);
return num;
-
-err_alloc:
- meta->num_tensors = 0;
- g_free (meta->dims);
- meta->dims = NULL;
- g_free (meta->types);
- meta->types = NULL;
- g_free (meta->ranks);
- meta->ranks = NULL;
- return 0;
}
/**
inputTensorSize = input_idx_list.size ();
for (int i = 0; i < inputTensorSize; i++) {
- if (getTensorDim (input_idx_list[i], inputDimension[i])) {
+ inputTensorRank[i] = NNS_TENSOR_RANK_LIMIT;
+
+ if (getTensorDim (input_idx_list[i], inputDimension[i],
+ &inputTensorRank[i])) {
return -1;
}
inputType[i] =
outputTensorSize = output_idx_list.size ();
for (int i = 0; i < outputTensorSize; i++) {
- if (getTensorDim (output_idx_list[i], outputDimension[i])) {
+ outputTensorRank[i] = NNS_TENSOR_RANK_LIMIT;
+
+ if (getTensorDim (output_idx_list[i], outputDimension[i],
+ &outputTensorRank[i])) {
return -1;
}
outputType[i] =
* @brief return the Dimension of Tensor.
* @param tensor_idx : the real index of model of the tensor
* @param[out] dim : the array of the tensor
+ * @param[out] rank : the rank of the tensor
* @return 0 if OK. non-zero if error.
*/
int
-TFLiteCore::getTensorDim (int tensor_idx, tensor_dim dim)
+TFLiteCore::getTensorDim (int tensor_idx, tensor_dim dim, unsigned int *rank)
{
int len = interpreter->tensor (tensor_idx)->dims->size;
+ *rank = len;
g_assert (len <= NNS_TENSOR_RANK_LIMIT);
/* the order of dimension is reversed at CAPS negotiation */
{
memcpy (dim, inputDimension[0], sizeof (tensor_dim));
*type = inputType[0];
+ printf ("[IN]\nDim: %d %d %d %d \nType: %d \nRank: %u\n",
+ inputDimension[0][0], inputDimension[0][1], inputDimension[0][2],
+ inputDimension[0][3], inputType[0], inputTensorRank[0]);
return inputTensorSize;
}
{
memcpy (dim, outputDimension[0], sizeof (tensor_dim));
*type = outputType[0];
+ printf ("[OUT]\nDim: %d %d %d %d \nType: %d \nRank: %u\n",
+ outputDimension[0][0], outputDimension[0][1], outputDimension[0][2],
+ outputDimension[0][3], outputType[0], outputTensorRank[0]);
return outputTensorSize;
}
int inputTensorSize; /**< The number of input tensors */
int outputTensorSize; /**< The number of output tensors */
+ unsigned int inputTensorRank[NNS_TENSOR_SIZE_LIMIT]; /**< The rank of input tensors */
+ unsigned int outputTensorRank[NNS_TENSOR_SIZE_LIMIT]; /**< The rank of output tensors */
+
std::unique_ptr < tflite::Interpreter > interpreter;
std::unique_ptr < tflite::FlatBufferModel > model;
double get_ms (struct timeval t);
_nns_tensor_type getTensorType (TfLiteType tfType);
- int getTensorDim (int tensor_idx, tensor_dim dim);
+ int getTensorDim (int tensor_idx, tensor_dim dim, unsigned int *rank);
};
/**
*/
typedef struct {
unsigned int num_tensors; /**< Number of tensors in each frame */
- tensor_dim *dims; /**< Array of tensor_dim, [num_tensors] */
- tensor_type *types; /**< Array of tensor_type, [num_tensors] */
- unsigned int *ranks; /**< Array of rank, [num_tensors] */
+ tensor_dim dims[NNS_TENSOR_SIZE_LIMIT]; /**< Array of tensor_dim, [num_tensors] */
+ tensor_type types[NNS_TENSOR_SIZE_LIMIT]; /**< Array of tensor_type, [num_tensors] */
+ unsigned int ranks[NNS_TENSOR_SIZE_LIMIT]; /**< Array of rank, [num_tensors] */
} GstTensor_TensorsMeta;
/**