From: Jihoon Lee Date: Mon, 28 Sep 2020 10:50:30 +0000 (+0900) Subject: [CS] s/draw_target/label + mode/ X-Git-Tag: accepted/tizen/unified/20201120.125454~92 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84400ef3db14a1fab3f1860845cb1cb7f0e08c0a;p=platform%2Fcore%2Fml%2Fnntrainer.git [CS] s/draw_target/label + mode/ This patch changes ad->draw_target to draw->label and draw->mode to incorporate with inference and training at the same time **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Jihoon Lee --- diff --git a/Applications/Tizen_native/CustomShortcut/inc/data.h b/Applications/Tizen_native/CustomShortcut/inc/data.h index 36a4298..1540c25 100644 --- a/Applications/Tizen_native/CustomShortcut/inc/data.h +++ b/Applications/Tizen_native/CustomShortcut/inc/data.h @@ -38,17 +38,20 @@ #define FEATURE_SIZE 62720 #define NUM_CLASS 2 -typedef enum DRAW_TARGET_ { - INFER = 0, - TRAIN_UNSET, - TRAIN_SMILE, - TRAIN_FROWN -} DRAW_TARGET; +typedef enum MODE_ { + MODE_INFER = 0, + MODE_TRAIN, +} MODE; + +typedef enum LABEL_ { + LABEL_SMILE = 0, + LABEL_FROWN, + LABEL_UNSET, +} LABEL; typedef struct appdata { Evas_Object *win; Evas_Object *conform; - Evas_Object *label; Evas_Object *naviframe; Elm_Object_Item *nf_it; Eext_Circle_Surface *circle_nf; @@ -67,8 +70,9 @@ 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 */ + MODE mode; /**< draw mode for the canvas */ + LABEL label; /**< target label, if infer mode, it is answer else label */ + int tries; /**< tells how many data has been labeled */ /**< Feature extraction related */ ml_pipeline_h pipeline; /**< handle of feature extractor */ @@ -133,12 +137,12 @@ void data_handle_path_data(appdata_s *ad, const char *data); /** * @brief update draw target from the data. currently the label is depending on - * ad->tries only + * ad->tries and ad->mode * * @param[in] ad appdata * @return int APP_ERROR_NONE if success */ -int data_update_draw_target(appdata_s *ad); +int data_update_label(appdata_s *ad); /** * @brief extract data feature from given model. diff --git a/Applications/Tizen_native/CustomShortcut/src/data.c b/Applications/Tizen_native/CustomShortcut/src/data.c index 0827263..984d057 100644 --- a/Applications/Tizen_native/CustomShortcut/src/data.c +++ b/Applications/Tizen_native/CustomShortcut/src/data.c @@ -152,7 +152,7 @@ static void on_feature_receive_(ml_tensors_data_h data, /// one-hot encoding. /// SMILE: 0 1 /// FROWN: 1 0 - bool target_label = ad->draw_target == TRAIN_SMILE ? 0 : 1; + bool target_label = ad->label == LABEL_SMILE ? 0 : 1; LOG_D("writing one-hot encoded label"); label = target_label; if (fwrite(&label, sizeof(float), 1, file) < 0) { @@ -251,19 +251,25 @@ PIPE_DESTORY: void data_handle_path_data(appdata_s *ad, const char *data) { /// handling path_data to check if it's for inference or path if (!strcmp(data, "inference")) { - ad->draw_target = INFER; + ad->mode = MODE_INFER; } else if (!strcmp(data, "train")) { - ad->draw_target = TRAIN_UNSET; + ad->mode = MODE_TRAIN; } + ad->label = LABEL_UNSET; } -int data_update_draw_target(appdata_s *ad) { +int data_update_label(appdata_s *ad) { + if (ad->mode == MODE_INFER) { + ad->label = LABEL_UNSET; + return APP_ERROR_NONE; + } + switch (ad->tries % NUM_CLASS) { case 0: - ad->draw_target = TRAIN_SMILE; + ad->label = LABEL_SMILE; return APP_ERROR_NONE; case 1: - ad->draw_target = TRAIN_FROWN; + ad->label = LABEL_FROWN; return APP_ERROR_NONE; default: LOG_E("Given label is unknown"); diff --git a/Applications/Tizen_native/CustomShortcut/src/main.c b/Applications/Tizen_native/CustomShortcut/src/main.c index 250f7a4..ab4c762 100644 --- a/Applications/Tizen_native/CustomShortcut/src/main.c +++ b/Applications/Tizen_native/CustomShortcut/src/main.c @@ -116,12 +116,17 @@ static int init_page_(appdata_s *ad, const char *path) { return status; } - view_set_canvas_clean(ad); + status = data_update_label(ad); + if (status != APP_ERROR_NONE) { + LOG_E("setting draw label failed"); + return status; + } - if (ad->draw_target == INFER) { + view_set_canvas_clean(ad); + if (ad->mode == MODE_INFER) { elm_layout_signal_callback_add(ad->layout, "draw/proceed", "", presenter_on_canvas_submit_inference, ad); - } else if (ad->draw_target == TRAIN_UNSET) { + } else if (ad->mode == MODE_TRAIN) { elm_layout_signal_callback_add(ad->layout, "draw/proceed", "", presenter_on_canvas_submit_training, ad); } else { @@ -189,9 +194,9 @@ void presenter_on_canvas_submit_training(void *data, Evas_Object *obj, appdata_s *ad = (appdata_s *)data; int status = APP_ERROR_NONE; - status = data_update_draw_target(ad); + status = data_update_label(ad); if (status != APP_ERROR_NONE) { - LOG_E("setting draw target failed"); + LOG_E("setting draw label failed"); return; } diff --git a/Applications/Tizen_native/CustomShortcut/src/view.c b/Applications/Tizen_native/CustomShortcut/src/view.c index 945cced..5423125 100644 --- a/Applications/Tizen_native/CustomShortcut/src/view.c +++ b/Applications/Tizen_native/CustomShortcut/src/view.c @@ -240,16 +240,14 @@ void view_set_canvas_clean(appdata_s *ad) { char emoji[5]; /// setting draw label and text - switch (ad->draw_target) { - case INFER: + switch (ad->label) { + case LABEL_UNSET: strcpy(emoji, "❓"); break; - case TRAIN_UNSET: - /// fall through intended - case TRAIN_SMILE: + case LABEL_SMILE: strcpy(emoji, "😊"); break; - case TRAIN_FROWN: + case LABEL_FROWN: strcpy(emoji, "😢"); break; default: