#define EDJ_PATH "edje/main.edj"
#define TRAIN_SET_PATH "trainingSet.dat"
+#define VALIDATION_SET_PATH "validationSet.dat"
-#define MAX_TRIES 5
+#define MAX_TRAIN_TRIES 5
+#define MAX_TRIES 10
-typedef enum _DRAW_MODE {
- INFER = 0,
- TRAIN_SMILE,
- TRAIN_SAD,
-} DRAW_MODE;
+#define FEATURE_SIZE 62720
+#define NUM_CLASS 2
typedef struct appdata {
Evas_Object *win;
Evas_Object *conform;
cairo_surface_t *cr_surface; /**< cairo surface for the canvas */
cairo_t *cr; /**< cairo engine for the canvas */
- DRAW_MODE mode; /**< drawing mode of current canvas */
int tries; /**< tells how many data has been labeled */
/**< ML related */
group {
name: "home";
parts {
- 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)
+ PART_TITLE("home/title", "NNTrainer Demo")
+ PART_BUTTON("home/proceed", "start draw", 0.1, 0.3, 0.9, 0.7)
}
programs {
- PROGRAM_BUTTON("home/to_train", "routes/to", "select")
- PROGRAM_BUTTON("home/to_test", "routes/to", "draw:inference")
+ PROGRAM_BUTTON("home/proceed", "routes/to", "draw")
}
}
group {
- name: "select";
- parts {
- PART_TITLE("select/title", "Select target emoji...")
- PART_BUTTON("select/sad", "😢", 0.1, 0.3, 0.45, 0.7)
- PART_BUTTON("select/smile", "😊", 0.55, 0.3, 0.9, 0.7)
- }
- programs {
- PROGRAM_BUTTON("select/smile", "routes/to", "draw:smile")
- PROGRAM_BUTTON("select/sad", "routes/to", "draw:sad")
- }
- }
- // this group is meant to be used for train / test, if it is not applicable, this group is reserved for training part
- group {
name: "draw";
parts {
- PART_TITLE("draw/title", "draw your symbol")
+ PART_TITLE("draw/title", "draw for 😊")
part {
name: "draw/canvas";
type: SWALLOW;
PART_BUTTON("train_result/go_back", "go back", 0.1, 0.3, 0.9, 0.7)
}
}
- 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
- }
- }
}
goto CLEAN;
}
- file = fopen(ad->pipe_dst, ad->tries == 1 ? "wb" : "wb+");
+ LOG_I("current tries %d", ad->tries);
+
+ if (ad->tries == MAX_TRAIN_TRIES || ad->tries == 0)
+ file = fopen(ad->pipe_dst, "wb+");
+ else
+ file = fopen(ad->pipe_dst, "ab+");
if (file == NULL) {
LOG_E("cannot open file");
goto CLEAN;
}
- if (write_result = fwrite(raw_data, data_size, 1, file) < 0) {
+ if ((write_result = fwrite(raw_data, 1, data_size, file)) < 0) {
LOG_E("write error happend");
}
if (write_result < data_size) {
- LOG_E("data was not fully written to file");
+ LOG_E("data was not fully written to file, result = %d, data_size = %d",
+ write_result, data_size);
}
- if (ad->mode != INFER) {
- LOG_D("writing label");
- label = ad->mode == TRAIN_SMILE ? 1 : 0;
- if (fwrite(&label, sizeof(float), 1, file) < 0) {
- LOG_E("write error happend");
- };
- }
+ bool target_label = ad->tries % 2;
+ LOG_D("writing one-hot encoded label");
+ label = target_label;
+ if (fwrite(&label, sizeof(float), 1, file) < 0) {
+ LOG_E("write error happend");
+ };
+
+ label = !target_label;
+ if (fwrite(&label, sizeof(float), 1, file) < 0) {
+ LOG_E("write error happend");
+ };
+
+ LOG_I("file dst: %s size: %ld", ad->pipe_dst, ftell(file));
if (fclose(file) < 0) {
LOG_E("there was error closing");
void data_train_model() {
ml_train_model_h model;
+
char model_conf_path[PATH_MAX];
char label_path[PATH_MAX];
int status = ML_ERROR_NONE;
goto CLEAN_UP;
}
+ freopen("out.txt", "a+", stdout);
+
status = ml_train_model_run(model, NULL);
if (status != ML_ERROR_NONE) {
LOG_E("run model failed %d", status);
int status = APP_ERROR_NONE;
char buf[256];
- ad->tries++;
- if (ad->mode != INFER) {
- LOG_D("labeling proceed");
- if (ad->tries >= MAX_TRIES) {
- ad->tries = 0;
- elm_naviframe_item_pop(ad->naviframe);
- data_train_model();
- view_routes_to(ad, "train_result");
- return;
- }
-
- sprintf(buf, "draw your symbol [%d/%d]", ad->tries, MAX_TRIES);
- elm_object_part_text_set(obj, "draw/title", buf);
- LOG_D("starting extraction");
-
- status = data_extract_feature(ad, TRAIN_SET_PATH, true);
- if (status != APP_ERROR_NONE) {
- LOG_E("feature extraction failed");
- }
- } else {
- LOG_D("infer proceed");
- status = data_extract_feature(ad, "test.dat", true);
- if (status != APP_ERROR_NONE) {
- LOG_E("feature extraction failed");
- }
-
- view_routes_to(ad, "test_result");
+ 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");
+ }
+
+ if (ad->tries == MAX_TRIES - 1) {
+ ad->tries = 0;
+ elm_naviframe_item_pop(ad->naviframe);
+ data_train_model();
+ view_routes_to(ad, "train_result");
+ return;
}
+ sprintf(buf, "draw for %s [%d/%d]", ad->tries % NUM_CLASS ? "😊" : "😢",
+ ad->tries + 2, MAX_TRIES);
+ elm_object_part_text_set(obj, "draw/title", buf);
+ LOG_D("starting extraction");
+
+ ad->tries++;
_canvas_erase_all(ad);
}
Evas_Object *frame = elm_layout_add(ad->layout);
- if (!strcmp(draw_mode, "inference")) {
- ad->mode = INFER;
- } else if (!strcmp(draw_mode, "smile")) {
- ad->mode = TRAIN_SMILE;
- } else if (!strcmp(draw_mode, "sad")) {
- ad->mode = TRAIN_SAD;
- }
-
status = elm_layout_content_set(ad->layout, "draw/canvas", frame);
if (status == EINA_FALSE) {
LOG_E("failed to get canvas object");