This patch shows inference to the page after evaluation.
**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>
*/
int util_save_drawing(cairo_surface_t *cr_surface, const char *dst);
+/**
+ * @brief get emoji string from LABEL enum
+ *
+ * @param[in] label label allocate outside.
+ * @param[out] emoji_str string emoticon from the enum. free after use
+ * @return int APP_ERROR_NONE if success;
+ */
+int util_get_emoji(LABEL label, char **emoji_str);
+
/**
* @brief handle given path_data. If data is invalid, it is essentially noop
*
*/
void view_update_result_cb(void *data, void *buffer, unsigned int nbytes);
+/**
+ * @brief update guess from the inference result
+ *
+ * @param[in] ad appdata
+ * @return int APP_ERROR_NONE if success
+ */
+void view_update_guess(void *ad);
+
#endif /* __nntrainer_example_custom_shortcut_view_H__ */
group {
name: "test_result";
parts {
- PART_TITLE("test_result/title", "eval successfully done")
- PART_BUTTON("test_result/go_back", "😊", 0.1, 0.3, 0.9, 0.7)
- // reserve a text area to show the guess from the model
+ PART_TITLE("test_result/title", "eval in progress")
+ part {
+ name: "test_result/label";
+ type: TEXT;
+ description {
+ state: "default" 0.0;
+ rel1.relative: 0.0 0.2;
+ rel2.relative: 1.0 0.8;
+ text {
+ text: "Guess...";
+ size: 100;
+ align: 0.5 0.5;
+ }
+ }
}
}
}
return APP_ERROR_NONE;
}
+int util_get_emoji(LABEL label, char **emoji_str) {
+ *emoji_str = (char *)malloc(sizeof(char) * 5);
+
+ /// setting draw label and text
+ switch (label) {
+ case LABEL_UNSET:
+ strcpy(*emoji_str, "❓");
+ return APP_ERROR_NONE;
+ case LABEL_SMILE:
+ strcpy(*emoji_str, "😊");
+ return APP_ERROR_NONE;
+ case LABEL_FROWN:
+ strcpy(*emoji_str, "😢");
+ return APP_ERROR_NONE;
+ default:
+ LOG_E("unreachable code");
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+ return APP_ERROR_INVALID_CONTEXT;
+}
+
+/************** data releated methods **********************/
+
static void on_feature_receive_(ml_tensors_data_h data,
const ml_tensors_info_h info, void *user_data) {
appdata_s *ad = (appdata_s *)user_data;
/// SMILE: 0 1
/// FROWN: 1 0
LOG_D("label: %lf %lf", raw_data[0], raw_data[1]);
+ ad->label = raw_data[0] < raw_data[1] ? LABEL_SMILE : LABEL_FROWN;
RESUME:
status = pthread_cond_signal(&ad->pipe_cond);
RESTORE_CB:
ecore_main_loop_thread_safe_call_async(¬ify_train_done, data);
+ return NULL;
+}
+
+static void *infer_(void *data) {
+ int status = ML_ERROR_NONE;
+ appdata_s *ad = (appdata_s *)data;
+
+ status = data_run_inference(ad);
+ if (status != ML_ERROR_NONE) {
+ LOG_E("inference process failed %d", status);
+ return NULL;
+ }
+
+ ecore_main_loop_thread_safe_call_async(view_update_guess, data);
return NULL;
}
const char *emission,
const char *source) {
appdata_s *ad = (appdata_s *)data;
- /** appdata handling NYI */
- data_run_inference(ad);
+ pthread_t infer_thread;
+ int status = 0;
ad->tries = 0;
elm_naviframe_item_pop(ad->naviframe);
- if (routes_to_(ad, "test_result") != 0)
+ if (routes_to_(ad, "test_result") != 0) {
+ LOG_E("routing to train thread failed");
return;
+ }
+
+ status = pthread_create(&infer_thread, NULL, infer_, data);
+ if (status != 0) {
+ LOG_E("creating pthread failed %s", strerror(errno));
+ return;
+ }
+ status = pthread_detach(infer_thread);
+ if (status < 0) {
+ LOG_E("detaching reading thread failed %s", strerror(errno));
+ pthread_cancel(infer_thread);
+ }
}
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_label(ad);
- if (status != APP_ERROR_NONE) {
- LOG_E("setting draw label failed");
- return;
- }
-
status = data_extract_feature(ad);
if (status != APP_ERROR_NONE) {
LOG_E("feature extraction failed");
/// prepare next canvas
ad->tries++;
+
+ status = data_update_label(ad);
+ if (status != APP_ERROR_NONE) {
+ LOG_E("setting draw label failed");
+ return;
+ }
+
view_set_canvas_clean(ad);
}
void view_set_canvas_clean(appdata_s *ad) {
char buf[256];
- char emoji[5];
-
- /// setting draw label and text
- switch (ad->label) {
- case LABEL_UNSET:
- strcpy(emoji, "❓");
- break;
- case LABEL_SMILE:
- strcpy(emoji, "😊");
- break;
- case LABEL_FROWN:
- strcpy(emoji, "😢");
- break;
- default:
- LOG_E("unreachable code");
- return;
+ char *emoji;
+
+ int status = util_get_emoji(ad->label, &emoji);
+ if (status != APP_ERROR_NONE) {
+ LOG_E("getting emoji failed %d", status);
+ return status;
}
+
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);
+ free(emoji);
+
/// clear cairo surface
cairo_set_source_rgba(ad->cr, 0.3, 0.3, 0.3, 0.2);
cairo_set_operator(ad->cr, CAIRO_OPERATOR_SOURCE);
snprintf(tmp, 255, "Loss: %.2f", result.train_loss);
elm_object_part_text_set(ad->layout, "train_progress/loss", tmp);
}
+
+void view_update_guess(void *data) {
+ appdata_s *ad = (appdata_s *)data;
+ char *emoji;
+ int status = util_get_emoji(ad->label, &emoji);
+ if (status != APP_ERROR_NONE) {
+ LOG_E("error getting emoji, reason: %d", status);
+ return status;
+ }
+
+ LOG_E("%s", emoji);
+ elm_object_part_text_set(ad->layout, "test_result/title",
+ "guess successfully done");
+ elm_object_part_text_set(ad->layout, "test_result/label", emoji);
+ free(emoji);
+
+ return status;
+}