[CS] Add inference page
authorJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 21 Sep 2020 05:41:51 +0000 (14:41 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 24 Sep 2020 07:16:44 +0000 (16:16 +0900)
**Changes proposed in this PR:**
- Change home to accomodate inference
- Route draw inference
- Add `draw_target` to use appdata to address label

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
Applications/Tizen_native/CustomShortcut/inc/data.h
Applications/Tizen_native/CustomShortcut/inc/main.h
Applications/Tizen_native/CustomShortcut/inc/view.h
Applications/Tizen_native/CustomShortcut/res/edje/main.edc
Applications/Tizen_native/CustomShortcut/src/data.c
Applications/Tizen_native/CustomShortcut/src/main.c
Applications/Tizen_native/CustomShortcut/src/view.c

index d37c1ab..1b45e31 100644 (file)
 
 #define FEATURE_SIZE 62720
 #define NUM_CLASS 2
+
+typedef enum DRAW_TARGET_ {
+  INFER = 0,
+  TRAIN_UNSET,
+  TRAIN_SMILE,
+  TRAIN_FROWN
+} DRAW_TARGET;
 typedef struct appdata {
   Evas_Object *win;
   Evas_Object *conform;
@@ -59,6 +66,7 @@ typedef struct appdata {
 
   cairo_surface_t *cr_surface; /**< cairo surface for the canvas */
   cairo_t *cr;                 /**< cairo engine for the canvas */
+  DRAW_TARGET draw_target;     /**< draw target for the canvas */
   int tries;                   /**< tells how many data has been labeled */
 
   /**< Feature extraction related */
index 4e51a37..1e0aac7 100644 (file)
@@ -1,4 +1,7 @@
+// SPDX-License-Identifier: Apache-2.0-only
 /**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
  * @file main.h
  * @date 14 May 2020
  * @brief TIZEN Native Example App main entry with NNTrainer/CAPI.
index 827db54..4a22334 100644 (file)
@@ -1,4 +1,7 @@
+// SPDX-License-Identifier: Apache-2.0-only
 /**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
  * @file view.h
  * @date 15 May 2020
  * @brief TIZEN Native Example App view entry with NNTrainer/CAPI.
index eba4fc8..82d7420 100644 (file)
@@ -1,4 +1,7 @@
+// SPDX-License-Identifier: Apache-2.0-only
 /**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
  * @file main.edc
  * @date 15 May 2020
  * @brief TIZEN Native Example App main edc that describes view behavior
@@ -94,11 +97,13 @@ collections {
   group {
     name: "home";
     parts {
-      PART_TITLE("home/title", "NNTrainer Demo")
-      PART_BUTTON("home/proceed", "start draw", 0.1, 0.3, 0.9, 0.7)
+      PART_TITLE("home/title", "Select actions...")
+      PART_BUTTON("home/to_train", "train", 0.55, 0.3, 0.9, 0.7)
+      PART_BUTTON("home/to_test", "test", 0.1, 0.3, 0.45, 0.7)
     }
     programs {
-      PROGRAM_BUTTON("home/proceed", "routes/to", "draw")
+      PROGRAM_BUTTON("home/to_train", "routes/to", "draw:train")
+      PROGRAM_BUTTON("home/to_test", "routes/to", "draw:inference")
     }
   }
   group {
@@ -152,6 +157,10 @@ collections {
             align: 0.5 0.5;
           }
         }
+        description {
+          state: "done" 0.0;
+          inherit: "default" 0.0;
+        }
       }
       part {
         name: "train_result/accuracy";
@@ -185,4 +194,12 @@ collections {
       }
     }
   }
+  group {
+    name: "test_result";
+    parts {
+      PART_TITLE("test_result/title", "test is successfully done")
+      PART_BUTTON("test_result/go_back", "test result: 😊", 0.1, 0.3, 0.9, 0.7)
+      // reserve a text area to show the guess from the model
+    }
+  }
 }
index 2477012..59d7938 100644 (file)
@@ -133,7 +133,10 @@ static void on_data_receive_(ml_tensors_data_h data,
           write_result, data_size);
   }
 
-  bool target_label = ad->tries % 2;
+  /// one-hot encoding.
+  /// SMILE: 0 1
+  /// FROWN: 1 0
+  bool target_label = ad->draw_target == TRAIN_SMILE ? 0 : 1;
   LOG_D("writing one-hot encoded label");
   label = target_label;
   if (fwrite(&label, sizeof(float), 1, file) < 0) {
index c1a3005..6379802 100644 (file)
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: Apache-2.0-only
 /**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
  * @file main.c
  * @date 14 May 2020
  * @brief TIZEN Native Example App main entry with NNTrainer/CAPI.
index 30d3c01..97c9be2 100644 (file)
@@ -1,4 +1,7 @@
+// SPDX-License-Identifier: Apache-2.0-only
 /**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
  * @file view.c
  * @date 15 May 2020
  * @brief TIZEN Native Example App view entry with NNTrainer/CAPI.
@@ -266,17 +269,57 @@ static void on_draw_reset_(void *data, Evas_Object *obj, const char *emission,
   canvas_erase_all_(ad);
 }
 
-static void on_draw_proceed_(void *data, Evas_Object *obj, const char *emission,
-                             const char *source) {
+static void set_draw_texts_(appdata_s *ad) {
+  char buf[256];
+  char emoji[5];
+  switch (ad->draw_target) {
+  case INFER:
+    strcpy(emoji, "❓");
+    break;
+  case TRAIN_UNSET:
+    /// fall through intended
+  case TRAIN_SMILE:
+    strcpy(emoji, "😊");
+    break;
+  case TRAIN_FROWN:
+    strcpy(emoji, "😢");
+    break;
+  default:
+    LOG_E("unreachable code");
+    return;
+  }
+  sprintf(buf, "draw for %s [%d/%d]", emoji, ad->tries + 1, MAX_TRIES);
+  elm_object_part_text_set(ad->layout, "draw/title", buf);
+  elm_object_part_text_set(ad->layout, "draw/label", emoji);
+}
+
+static void on_draw_proceed_infer_(void *data, Evas_Object *obj,
+                                   const char *emission, const char *source) {
+  view_routes_to((appdata_s *)data, "test_result");
+}
+
+static void on_draw_proceed_train_(void *data, Evas_Object *obj,
+                                   const char *emission, const char *source) {
   appdata_s *ad = (appdata_s *)data;
   int status = APP_ERROR_NONE;
 
-  char buf[256];
+  switch (ad->tries % NUM_CLASS) {
+  case 0:
+    ad->draw_target = TRAIN_SMILE;
+    break;
+  case 1:
+    ad->draw_target = TRAIN_FROWN;
+    break;
+  default:
+    LOG_E("Given label is unknown");
+    return;
+  }
 
   LOG_D("labeling proceed");
   status = data_extract_feature(
     ad, ad->tries < MAX_TRAIN_TRIES ? TRAIN_SET_PATH : VALIDATION_SET_PATH,
     true);
+
   if (status != APP_ERROR_NONE) {
     LOG_E("feature extraction failed");
   }
@@ -288,13 +331,9 @@ static void on_draw_proceed_(void *data, Evas_Object *obj, const char *emission,
     return;
   }
 
-  const char *emoji = ad->tries % NUM_CLASS ? "😊" : "😢";
-  sprintf(buf, "draw for %s [%d/%d]", emoji, ad->tries + 2, MAX_TRIES);
-  elm_object_part_text_set(obj, "draw/title", buf);
-  elm_object_part_text_set(obj, "draw/label", emoji);
-  LOG_D("starting extraction");
-
+  /// prepare next canvas
   ad->tries++;
+  set_draw_texts_(ad);
   canvas_erase_all_(ad);
 }
 
@@ -379,9 +418,17 @@ static int create_canvas_(appdata_s *ad, const char *draw_mode) {
   elm_layout_signal_callback_add(ad->layout, "draw/reset", "", on_draw_reset_,
                                  ad);
 
-  elm_layout_signal_callback_add(ad->layout, "draw/proceed", "",
-                                 on_draw_proceed_, ad);
+  if (!strcmp(draw_mode, "inference")) {
+    ad->draw_target = INFER;
+    elm_layout_signal_callback_add(ad->layout, "draw/proceed", "",
+                                   on_draw_proceed_infer_, ad);
+  } else if (!strcmp(draw_mode, "train")) {
+    ad->draw_target = TRAIN_UNSET;
+    elm_layout_signal_callback_add(ad->layout, "draw/proceed", "",
+                                   on_draw_proceed_train_, ad);
+  }
 
+  set_draw_texts_(ad);
   ad->tries = 0;
   ad->canvas = canvas;
   ad->cr_surface = cairo_surface;