Fixup Input Tensor dims format (NHWC) (#1040)
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 5 Nov 2021 08:53:27 +0000 (17:53 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 15 Dec 2021 10:50:17 +0000 (19:50 +0900)
[Problem] Input Tensor's dimension should be in NHWC format
[Solution] Add batch and channel sizes

```bash
sh-3.2# beyond-tizen-capi-test --gtest_filter=*inference*
Running main() from /home/abuild/rpmbuild/BUILD/gtest-1.10.0/googletest/src/gtest_main.cc
Note: Google Test filter = *inference*
[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from inference
[ RUN      ] inference.positive_beyond_inference_create_with_nullarg
[       OK ] inference.positive_beyond_inference_create_with_nullarg (1 ms)
[ RUN      ] inference.positive_beyond_inference_create
[       OK ] inference.positive_beyond_inference_create (0 ms)
[ RUN      ] inference.positive_beyond_inference_get_input_tensor_info_Runtime
** Message: 12:19:44.941: accl = cpu
[       OK ] inference.positive_beyond_inference_get_input_tensor_info_Runtime (174 ms)
[----------] 3 tests from inference (175 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (175 ms total)
[  PASSED  ] 3 tests.
```

Change-Id: Ia8a180bc4548da2f5e8487dd7fd121df47b2a4f4
Signed-off-by: Sung-jae Park <nicesj.park@samsung.com>
subprojects/libbeyond-peer_nn/src/peer.cc
subprojects/libbeyond-tizen-capi/ut/unittest_inference.cc

index 2616e81cd34025ce838c8ae7cd2e7cbc35c23642..7d2196455f95ad55662ec27102b6b0a6ac5155fd 100644 (file)
@@ -36,7 +36,7 @@
 
 #define DEFAULT_FRAMEWORK "tensorflow-lite"
 #define CONFIGURED_INPUT_TENSOR_SIZE 1
-#define CONFIGURED_INPUT_TENSOR_DIMS 2
+#define CONFIGURED_INPUT_TENSOR_DIMS 4
 
 // TODO:
 // We have to update the sizeMap with more precise values for each of image format
@@ -322,7 +322,7 @@ beyond_tensor_info *Peer::AllocInputTensorInfo(beyond_input_config *config)
     }
 
     // NOTE:
-    // WIDTH and HEIGHT, dimension size is always 2
+    // BATCH, WIDTH, HEIGHT and CHANNEL, dimension size is always 4
     info->dims = static_cast<beyond_tensor_info::dimensions *>(malloc(sizeof(beyond_tensor_info::dimensions) + sizeof(int) * CONFIGURED_INPUT_TENSOR_DIMS));
     if (info->dims == nullptr) {
         ErrPrintCode(errno, "malloc");
@@ -336,10 +336,12 @@ beyond_tensor_info *Peer::AllocInputTensorInfo(beyond_input_config *config)
     // This array information should be updated for each image format specification
     // In case of the YUV, it could be manipulatd as a 3 dimensional array buffer
     // At least now, image format related buffer layout will be treated as a 2-dimensional
-    // array (width and height) buffer
+    // array (height and width) buffer
     info->dims->size = CONFIGURED_INPUT_TENSOR_DIMS;
-    info->dims->data[0] = imageConfig->width;
+    info->dims->data[0] = 1;
     info->dims->data[1] = imageConfig->height;
+    info->dims->data[2] = imageConfig->width;
+    info->dims->data[3] = it->second;
     return info;
 }
 
index 2809fbf8d286dc6899e2dc0ca3aa858df105bdfc..d45c09cb96f2f80cb27793971a704fdaf4491aaf 100644 (file)
@@ -144,9 +144,11 @@ TEST(inference, positive_beyond_inference_get_input_tensor_info_Runtime)
     ASSERT_EQ(input_info->type, BEYOND_TENSOR_TYPE_UINT8);
     ASSERT_EQ(input_info->size, 320 * 192 * 3);
     ASSERT_NE(input_info->dims, nullptr);
-    ASSERT_EQ(input_info->dims->size, 2);
-    ASSERT_EQ(input_info->dims->data[0], 320);
+    ASSERT_EQ(input_info->dims->size, 4);
+    ASSERT_EQ(input_info->dims->data[0], 1);
     ASSERT_EQ(input_info->dims->data[1], 192);
+    ASSERT_EQ(input_info->dims->data[2], 320);
+    ASSERT_EQ(input_info->dims->data[3], 3);
 
     (void)beyond_peer_deactivate(peerEdgeHandle);
     (void)beyond_inference_remove_peer(inferenceHandle, peerHandle);