From 1dac29d9a076f809cadb320797d96fed731cdffc Mon Sep 17 00:00:00 2001 From: mercat Date: Wed, 11 Sep 2019 15:49:56 +0300 Subject: [PATCH] Clean version of machine learning constraint code. (ICIP paper) --- build/kvazaar_lib/kvazaar_lib.vcxproj | 4 + build/kvazaar_lib/kvazaar_lib.vcxproj.filters | 15 + src/Makefile.am | 4 + src/cfg.c | 5 + src/cli.c | 6 +- src/constraint.c | 8 +- src/constraint.h | 8 +- src/encoder_state-ctors_dtors.c | 2 +- src/encoderstate.c | 3 +- src/kvazaar.h | 3 + src/ml_intra_cu_depth_pred.c | 834 +++++++++++++++++- src/ml_intra_cu_depth_pred.h | 2 - src/search.c | 2 - 13 files changed, 862 insertions(+), 34 deletions(-) diff --git a/build/kvazaar_lib/kvazaar_lib.vcxproj b/build/kvazaar_lib/kvazaar_lib.vcxproj index 78b81a2a..17e65254 100644 --- a/build/kvazaar_lib/kvazaar_lib.vcxproj +++ b/build/kvazaar_lib/kvazaar_lib.vcxproj @@ -138,6 +138,7 @@ + @@ -159,6 +160,7 @@ + @@ -199,6 +201,7 @@ + @@ -259,6 +262,7 @@ + diff --git a/build/kvazaar_lib/kvazaar_lib.vcxproj.filters b/build/kvazaar_lib/kvazaar_lib.vcxproj.filters index b8d487ea..d4acfbb2 100644 --- a/build/kvazaar_lib/kvazaar_lib.vcxproj.filters +++ b/build/kvazaar_lib/kvazaar_lib.vcxproj.filters @@ -52,6 +52,9 @@ {f4abece9-e209-4817-a57e-c64ca7c5e05c} + + {895fc8cc-6f08-49a7-b377-b5c38a44d1b1} + @@ -239,6 +242,12 @@ Threadwrapper + + Constraint + + + Constraint + @@ -453,6 +462,12 @@ Threadwrapper + + Constraint + + + Constraint + diff --git a/src/Makefile.am b/src/Makefile.am index 7f3a54d2..bacd9567 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,6 +53,8 @@ libkvazaar_la_SOURCES = \ checkpoint.h \ cfg.c \ cfg.h \ + constraint.c \ + constraint.h \ context.c \ context.h \ cu.c \ @@ -85,6 +87,8 @@ libkvazaar_la_SOURCES = \ kvazaar.c \ kvazaar_internal.h \ kvz_math.h \ + ml_intra_cu_depth_pred.c \ + ml_intra_cu_depth_pred.h \ nal.c \ nal.h \ rate_control.c \ diff --git a/src/cfg.c b/src/cfg.c index 950a0af1..b2eae143 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -141,6 +141,8 @@ int kvz_config_init(kvz_config *cfg) cfg->max_merge = 5; cfg->early_skip = true; + cfg->ml_pu_depth_intra = false; + return 1; } @@ -1260,6 +1262,9 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) else if OPT("early-skip") { cfg->early_skip = (bool)atobool(value); } + else if OPT("ml-pu-depth-intra") { + cfg->ml_pu_depth_intra = (bool)atobool(value); + } else { return 0; } diff --git a/src/cli.c b/src/cli.c index ebb68729..a2aea628 100644 --- a/src/cli.c +++ b/src/cli.c @@ -137,7 +137,8 @@ static const struct option long_options[] = { { "max-merge", required_argument, NULL, 0 }, { "early-skip", no_argument, NULL, 0 }, { "no-early-skip", no_argument, NULL, 0 }, - {0, 0, 0, 0} + { "ml-pu-depth-intra", no_argument, NULL, 0 }, + {0, 0, 0, 0} }; /** @@ -478,6 +479,9 @@ void print_help(void) " - 0, 1, 2, 3: from 64x64 to 8x8\n" " --pu-depth-intra - : Intra prediction units sizes [1-4]\n" " - 0, 1, 2, 3, 4: from 64x64 to 4x4\n" + " --ml-pu-depth-intra : Predict the pu-depth-intra using machine\n" + " learning trees, overrides the\n" + " --pu-depth-intra parameter. [disabled]\n" " --tr-depth-intra : Transform split depth for intra blocks [0]\n" " --(no-)bipred : Bi-prediction [disabled]\n" " --cu-split-termination : CU split search termination [zero]\n" diff --git a/src/constraint.c b/src/constraint.c index 1fe7ab3b..1abec967 100644 --- a/src/constraint.c +++ b/src/constraint.c @@ -26,7 +26,7 @@ * \param state encoder state * \return the pointer of constraint_t structure */ -void * kvz_init_const(encoder_state_t* state) { +void * kvz_init_constraint(encoder_state_t* state, encoder_control_t * const encoder) { constraint_t* constr = NULL; // Allocate the constraint_t strucutre constr = MALLOC(constraint_t, 1); @@ -37,7 +37,7 @@ void * kvz_init_const(encoder_state_t* state) { // Allocate the ml_intra_ctu_pred_t structure constr->ml_intra_depth_ctu = NULL; - if (E_CONSTRAINT == 1) // TODO: Change this by a new param !! + if (encoder->cfg.ml_pu_depth_intra) // TODO: Change this by a new param !! { constr->ml_intra_depth_ctu = kvz_init_ml_intra_depth_const(); } @@ -49,9 +49,9 @@ void * kvz_init_const(encoder_state_t* state) { * * \param state encoder state */ -void kvz_end_const(encoder_state_t* state) { +void kvz_constraint_free(encoder_state_t* state) { constraint_t* constr = state->constraint; - if (E_CONSTRAINT == 1) // TODO: Change this by a new param !! + if (constr->ml_intra_depth_ctu) { kvz_end_ml_intra_depth_const(constr->ml_intra_depth_ctu); } diff --git a/src/constraint.h b/src/constraint.h index 424948d1..b01d6178 100644 --- a/src/constraint.h +++ b/src/constraint.h @@ -23,10 +23,10 @@ #include "ml_intra_cu_depth_pred.h" #include "encoderstate.h" -#define E_CONSTRAINT 1 /* Constraint structure: - Each field corresponds to a constraint technique. The encoder tests if the constraint pointer is allocated to apply the technique. + * Each field corresponds to a constraint technique. The encoder tests if the constraint + * pointer is allocated to apply the technique. */ typedef struct { // Structure used for the CTU depth prediction using Machine Learning in All Intra @@ -34,7 +34,7 @@ typedef struct { } constraint_t; -void * kvz_init_const(encoder_state_t* state); -void kvz_end_const(encoder_state_t* state); +void * kvz_init_constraint(encoder_state_t* state, encoder_control_t * const encoder); +void kvz_constraint_free(encoder_state_t* state); #endif \ No newline at end of file diff --git a/src/encoder_state-ctors_dtors.c b/src/encoder_state-ctors_dtors.c index 7f13bafe..7fb46e1b 100644 --- a/src/encoder_state-ctors_dtors.c +++ b/src/encoder_state-ctors_dtors.c @@ -708,7 +708,7 @@ void kvz_encoder_state_finalize(encoder_state_t * const state) { if (!state->parent) { // End of the constraint structure - kvz_end_const(state); + kvz_constraint_free(state); } kvz_bitstream_finalize(&state->stream); diff --git a/src/encoderstate.c b/src/encoderstate.c index 10d494d7..995086c2 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -1164,6 +1164,7 @@ static void encoder_state_init_children(encoder_state_t * const state) { kvz_threadqueue_free_job(&state->tqj_recon_done); //Copy the constraint pointer + // TODO: Try to do it in the if (state->is_leaf) if (state->parent != NULL) { state->constraint = state->parent->constraint; } @@ -1342,7 +1343,7 @@ void kvz_encoder_prepare(encoder_state_t *state) assert(state->frame->done); // Intialization of the constraint structure - state->constraint = kvz_init_const(state->constraint); + state->constraint = kvz_init_constraint(state->constraint, encoder); if (state->frame->num == -1) { diff --git a/src/kvazaar.h b/src/kvazaar.h index 96838621..444cedb0 100644 --- a/src/kvazaar.h +++ b/src/kvazaar.h @@ -390,6 +390,9 @@ typedef struct kvz_config /** \brief Enable Early Skip Mode Decision */ uint8_t early_skip; + /** \brief Enable Machine learning CU depth prediction for Intra encoding. */ + uint8_t ml_pu_depth_intra; + } kvz_config; /** diff --git a/src/ml_intra_cu_depth_pred.c b/src/ml_intra_cu_depth_pred.c index 78446faa..99b1a897 100644 --- a/src/ml_intra_cu_depth_pred.c +++ b/src/ml_intra_cu_depth_pred.c @@ -21,19 +21,793 @@ #include "ml_intra_cu_depth_pred.h" -static tree_predict predict_func_merge[4] = { - tree_predict_merge_depth_1, - tree_predict_merge_depth_2, - tree_predict_merge_depth_3, - tree_predict_merge_depth_4 -}; +int tree_predict_merge_depth_1(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->merge_variance <= 140.3129) + { + if (p_features->var_of_sub_var <= 569.6553) + { + if (p_features->merge_variance <= 20.8854) + { + *p_nb_iter = 19428.0; + *p_nb_bad = 1740.0; + return -1.0000; + } + else if (p_features->sub_variance_0 <= 9.1015) + { + if (p_features->merge_variance <= 39.132) + { + *p_nb_iter = 1166.0; + *p_nb_bad = 358.0; + return -1.0000; + } + else { + *p_nb_iter = 1049.0; + *p_nb_bad = 392.0; + return 1.0000; + } + } + else { + *p_nb_iter = 9371.0; + *p_nb_bad = 1805.0; + return -1.0000; + } + } + else if (p_features->sub_variance_2 <= 23.3193) + { + *p_nb_iter = 1059.0; + *p_nb_bad = 329.0; + return 1.0000; + } + else if (p_features->sub_variance_1 <= 30.7348) + { + *p_nb_iter = 1042.0; + *p_nb_bad = 395.0; + return 1.0000; + } + else { + *p_nb_iter = 1756.0; + *p_nb_bad = 588.0; + return -1.0000; + } + } + else if (p_features->merge_variance <= 857.8047) + { + if (p_features->var_of_sub_var <= 66593.5553) + { + if (p_features->sub_variance_0 <= 12.1697) + { + *p_nb_iter = 2006.0; + *p_nb_bad = 374.0; + return 1.0000; + } + else if (p_features->neigh_variance_C <= 646.8204) + { + if (p_features->neigh_variance_A <= 664.7609) + { + if (p_features->neigh_variance_B <= 571.2004) + { + if (p_features->var_of_sub_mean <= 4.1069) + { + *p_nb_iter = 1208.0; + *p_nb_bad = 399.0; + return 1.0000; + } + else if (p_features->var_of_sub_var <= 11832.6635) + { + *p_nb_iter = 8701.0; + *p_nb_bad = 3037.0; + return -1.0000; + } + else if (p_features->neigh_variance_A <= 142.298) + { + *p_nb_iter = 1025.0; + *p_nb_bad = 290.0; + return 1.0000; + } + else if (p_features->variance <= 394.4839) + { + *p_nb_iter = 1156.0; + *p_nb_bad = 489.0; + return 1.0000; + } + else { + *p_nb_iter = 1150.0; + *p_nb_bad = 503.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1777.0; + *p_nb_bad = 558.0; + return 1.0000; + } + } + else { + *p_nb_iter = 1587.0; + *p_nb_bad = 411.0; + return 1.0000; + } + } + else { + *p_nb_iter = 1980.0; + *p_nb_bad = 474.0; + return 1.0000; + } + } + else { + *p_nb_iter = 3613.0; + *p_nb_bad = 475.0; + return 1.0000; + } + } + else { + *p_nb_iter = 20926.0; + *p_nb_bad = 1873.0; + return 1.0000; + } +} + + + +int tree_predict_merge_depth_2(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->merge_variance <= 119.4611) + { + if (p_features->var_of_sub_var <= 1078.0638) + { + if (p_features->neigh_variance_B <= 70.2189) + { + *p_nb_iter = 29253.0; + *p_nb_bad = 3837.0; + return -1.0000; + } + else if (p_features->variance <= 20.8711) + { + *p_nb_iter = 1292.0; + *p_nb_bad = 458.0; + return 2.0000; + } + else { + *p_nb_iter = 1707.0; + *p_nb_bad = 399.0; + return -1.0000; + } + } + else if (p_features->var_of_sub_var <= 3300.4034) + { + *p_nb_iter = 1554.0; + *p_nb_bad = 675.0; + return -1.0000; + } + else { + *p_nb_iter = 1540.0; + *p_nb_bad = 429.0; + return 2.0000; + } + } + else if (p_features->merge_variance <= 696.1989) + { + if (p_features->var_of_sub_var <= 31803.3242) + { + if (p_features->sub_variance_2 <= 10.3845) + { + *p_nb_iter = 3473.0; + *p_nb_bad = 768.0; + return 2.0000; + } + else if (p_features->neigh_variance_C <= 571.5329) + { + if (p_features->neigh_variance_B <= 492.8159) + { + if (p_features->neigh_variance_B <= 38.9672) + { + *p_nb_iter = 1887.0; + *p_nb_bad = 588.0; + return 2.0000; + } + else if (p_features->neigh_variance_A <= 380.5927) + { + if (p_features->sub_variance_1 <= 19.9678) + { + *p_nb_iter = 1686.0; + *p_nb_bad = 721.0; + return 2.0000; + } + else if (p_features->neigh_variance_A <= 66.6749) + { + *p_nb_iter = 1440.0; + *p_nb_bad = 631.0; + return 2.0000; + } + else { + *p_nb_iter = 5772.0; + *p_nb_bad = 2031.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1791.0; + *p_nb_bad = 619.0; + return 2.0000; + } + } + else { + *p_nb_iter = 1624.0; + *p_nb_bad = 494.0; + return 2.0000; + } + } + else { + *p_nb_iter = 1298.0; + *p_nb_bad = 312.0; + return 2.0000; + } + } + else { + *p_nb_iter = 4577.0; + *p_nb_bad = 892.0; + return 2.0000; + } + } + else { + *p_nb_iter = 21106.0; + *p_nb_bad = 2744.0; + return 2.0000; + } +} + + + +int tree_predict_merge_depth_3(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->merge_variance <= 80.1487) + { + if (p_features->neigh_variance_C <= 83.7148) + { + *p_nb_iter = 29806.0; + *p_nb_bad = 3603.0; + return -1.0000; + } + else { + *p_nb_iter = 1003.0; + *p_nb_bad = 421.0; + return 3.0000; + } + } + else if (p_features->merge_variance <= 351.8138) + { + if (p_features->neigh_variance_C <= 255.4236) + { + if (p_features->neigh_variance_B <= 260.5349) + { + if (p_features->var_of_sub_var <= 6381.513) + { + if (p_features->neigh_variance_A <= 244.2556) + { + if (p_features->sub_variance_0 <= 4.75) + { + *p_nb_iter = 1290.0; + *p_nb_bad = 525.0; + return 3.0000; + } + else if (p_features->neigh_variance_B <= 16.9287) + { + *p_nb_iter = 1045.0; + *p_nb_bad = 499.0; + return 3.0000; + } + else { + *p_nb_iter = 6901.0; + *p_nb_bad = 2494.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1332.0; + *p_nb_bad = 408.0; + return 3.0000; + } + } + else { + *p_nb_iter = 2929.0; + *p_nb_bad = 842.0; + return 3.0000; + } + } + else { + *p_nb_iter = 2239.0; + *p_nb_bad = 572.0; + return 3.0000; + } + } + else { + *p_nb_iter = 2777.0; + *p_nb_bad = 714.0; + return 3.0000; + } + } + else { + *p_nb_iter = 30678.0; + *p_nb_bad = 5409.0; + return 3.0000; + } +} + + + +int tree_predict_merge_depth_4(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->neigh_variance_C <= 240.2773) + { + if (p_features->neigh_variance_B <= 227.5898) + { + if (p_features->neigh_variance_A <= 195.4844) + { + if (p_features->variance <= 203.3086) + { + if (p_features->qp <= 32) + { + if (p_features->neigh_variance_C <= 102.2344) + { + if (p_features->neigh_variance_B <= 116.4961) + { + if (p_features->variance <= 89.4023) + { + *p_nb_iter = 27398.0; + *p_nb_bad = 4665.0; + return -1.0000; + } + else { + *p_nb_iter = 1676.0; + *p_nb_bad = 795.0; + return 4.0000; + } + } + else { + *p_nb_iter = 1405.0; + *p_nb_bad = 566.0; + return 4.0000; + } + } + else { + *p_nb_iter = 2827.0; + *p_nb_bad = 1173.0; + return 4.0000; + } + } + else { + *p_nb_iter = 8871.0; + *p_nb_bad = 822.0; + return -1.0000; + } + } + else { + *p_nb_iter = 3162.0; + *p_nb_bad = 718.0; + return 4.0000; + } + } + else { + *p_nb_iter = 6154.0; + *p_nb_bad = 1397.0; + return 4.0000; + } + } + else { + *p_nb_iter = 9385.0; + *p_nb_bad = 1609.0; + return 4.0000; + } + } + else { + *p_nb_iter = 19122.0; + *p_nb_bad = 2960.0; + return 4.0000; + } +} + + + +int tree_predict_split_depth_0(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->var_of_sub_var <= 12754.7856) + { + if (p_features->var_of_sub_var <= 137.9034) + { + *p_nb_iter = 25155.0; + *p_nb_bad = 2959.0; + return 0.0000; + } + else if (p_features->sub_variance_2 <= 13.2892) + { + *p_nb_iter = 1080.0; + *p_nb_bad = 383.0; + return -1.0000; + } + else if (p_features->variance <= 564.1738) + { + if (p_features->var_of_sub_var <= 1185.4728) + { + *p_nb_iter = 6067.0; + *p_nb_bad = 1699.0; + return 0.0000; + } + else if (p_features->var_of_sub_mean <= 46.2388) + { + if (p_features->sub_variance_0 <= 46.8708) + { + *p_nb_iter = 1088.0; + *p_nb_bad = 377.0; + return -1.0000; + } + else if (p_features->sub_variance_3 <= 61.4213) + { + *p_nb_iter = 1183.0; + *p_nb_bad = 498.0; + return -1.0000; + } + else { + *p_nb_iter = 3416.0; + *p_nb_bad = 1373.0; + return 0.0000; + } + } + else { + *p_nb_iter = 3769.0; + *p_nb_bad = 1093.0; + return 0.0000; + } + } + else { + *p_nb_iter = 1036.0; + *p_nb_bad = 434.0; + return -1.0000; + } + } + else if (p_features->var_of_sub_var <= 98333.8279) + { + if (p_features->variance <= 987.2333) + { + if (p_features->var_of_sub_var <= 37261.2896) + { + if (p_features->variance <= 238.2248) + { + *p_nb_iter = 1323.0; + *p_nb_bad = 301.0; + return -1.0000; + } + else if (p_features->var_of_sub_var <= 17347.3971) + { + *p_nb_iter = 1215.0; + *p_nb_bad = 550.0; + return 0.0000; + } + else if (p_features->qp <= 22) + { + *p_nb_iter = 1000.0; + *p_nb_bad = 493.0; + return 0.0000; + } + else { + *p_nb_iter = 2640.0; + *p_nb_bad = 1121.0; + return -1.0000; + } + } + else { + *p_nb_iter = 5188.0; + *p_nb_bad = 1248.0; + return -1.0000; + } + } + else { + *p_nb_iter = 2323.0; + *p_nb_bad = 274.0; + return -1.0000; + } + } + else { + *p_nb_iter = 21357.0; + *p_nb_bad = 1829.0; + return -1.0000; + } +} + + +int tree_predict_split_depth_1(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->var_of_sub_var <= 1138.9473) + { + *p_nb_iter = 32445.0; + *p_nb_bad = 4580.0; + return 1.0000; + } + else if (p_features->var_of_sub_var <= 27289.2117) + { + if (p_features->sub_variance_1 <= 12.0603) + { + *p_nb_iter = 1900.0; + *p_nb_bad = 401.0; + return -1.0000; + } + else if (p_features->var_of_sub_var <= 5841.4773) + { + if (p_features->variance <= 72.4175) + { + *p_nb_iter = 1000.0; + *p_nb_bad = 356.0; + return -1.0000; + } + else if (p_features->neigh_variance_A <= 633.8163) + { + *p_nb_iter = 5279.0; + *p_nb_bad = 1961.0; + return 1.0000; + } + else { + *p_nb_iter = 1176.0; + *p_nb_bad = 527.0; + return -1.0000; + } + } + else if (p_features->sub_variance_0 <= 38.3035) + { + *p_nb_iter = 1251.0; + *p_nb_bad = 293.0; + return -1.0000; + } + else if (p_features->neigh_variance_B <= 664.9494) + { + if (p_features->sub_variance_3 <= 45.8181) + { + *p_nb_iter = 1276.0; + *p_nb_bad = 471.0; + return -1.0000; + } + else if (p_features->sub_variance_3 <= 404.3086) + { + if (p_features->sub_variance_1 <= 99.8715) + { + *p_nb_iter = 1005.0; + *p_nb_bad = 435.0; + return -1.0000; + } + else if (p_features->sub_variance_0 <= 282.3064) + { + *p_nb_iter = 1370.0; + *p_nb_bad = 539.0; + return 1.0000; + } + else { + *p_nb_iter = 1013.0; + *p_nb_bad = 495.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1000.0; + *p_nb_bad = 379.0; + return -1.0000; + } + } + else { + *p_nb_iter = 2270.0; + *p_nb_bad = 679.0; + return -1.0000; + } + } + else { + *p_nb_iter = 29015.0; + *p_nb_bad = 3950.0; + return -1.0000; + } +} + + +int tree_predict_split_depth_2(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->var_of_sub_var <= 2597.4529) + { + if (p_features->var_of_sub_var <= 146.7734) + { + *p_nb_iter = 23216.0; + *p_nb_bad = 1560.0; + return 2.0000; + } + else if (p_features->merge_variance <= 259.6952) + { + *p_nb_iter = 7470.0; + *p_nb_bad = 1902.0; + return 2.0000; + } + else if (p_features->qp <= 27) + { + if (p_features->variance <= 73.9929) + { + *p_nb_iter = 1138.0; + *p_nb_bad = 486.0; + return -1.0000; + } + else { + *p_nb_iter = 1619.0; + *p_nb_bad = 716.0; + return 2.0000; + } + } + else { + *p_nb_iter = 2425.0; + *p_nb_bad = 861.0; + return 2.0000; + } + } + else if (p_features->var_of_sub_var <= 60850.5208) + { + if (p_features->var_of_sub_var <= 10144.602) + { + if (p_features->neigh_variance_C <= 926.8972) + { + if (p_features->sub_variance_0 <= 26.6006) + { + *p_nb_iter = 1796.0; + *p_nb_bad = 586.0; + return -1.0000; + } + else if (p_features->neigh_variance_A <= 493.5849) + { + if (p_features->neigh_variance_A <= 72.9516) + { + *p_nb_iter = 1326.0; + *p_nb_bad = 557.0; + return -1.0000; + } + else if (p_features->variance <= 156.4014) + { + *p_nb_iter = 1210.0; + *p_nb_bad = 563.0; + return -1.0000; + } + else { + *p_nb_iter = 1920.0; + *p_nb_bad = 817.0; + return 2.0000; + } + } + else { + *p_nb_iter = 1106.0; + *p_nb_bad = 437.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1001.0; + *p_nb_bad = 278.0; + return -1.0000; + } + } + else { + *p_nb_iter = 13068.0; + *p_nb_bad = 3612.0; + return -1.0000; + } + } + else { + *p_nb_iter = 22705.0; + *p_nb_bad = 2687.0; + return -1.0000; + } +} + + + +int tree_predict_split_depth_3(features_s* p_features, double* p_nb_iter, double* p_nb_bad) +{ + if (p_features->var_of_sub_var <= 818.5173) + { + if (p_features->merge_variance <= 62.7641) + { + *p_nb_iter = 20568.0; + *p_nb_bad = 767.0; + return 3.0000; + } + else if (p_features->qp <= 27) + { + if (p_features->variance <= 9.4219) + { + *p_nb_iter = 1255.0; + *p_nb_bad = 206.0; + return 3.0000; + } + else if (p_features->merge_variance <= 375.2185) + { + *p_nb_iter = 3999.0; + *p_nb_bad = 1321.0; + return 3.0000; + } + else { + *p_nb_iter = 1786.0; + *p_nb_bad = 817.0; + return -1.0000; + } + } + else { + *p_nb_iter = 5286.0; + *p_nb_bad = 737.0; + return 3.0000; + } + } + else if (p_features->var_of_sub_var <= 37332.3018) + { + if (p_features->var_of_sub_var <= 7585.0282) + { + if (p_features->qp <= 32) + { + if (p_features->neigh_variance_C <= 330.2178) + { + if (p_features->sub_variance_0 <= 8.5273) + { + *p_nb_iter = 1114.0; + *p_nb_bad = 346.0; + return -1.0000; + } + else if (p_features->neigh_variance_B <= 221.5469) + { + if (p_features->var_of_sub_var <= 1989.7928) + { + *p_nb_iter = 1539.0; + *p_nb_bad = 606.0; + return 3.0000; + } + else if (p_features->variance <= 155.5974) + { + *p_nb_iter = 1298.0; + *p_nb_bad = 634.0; + return 3.0000; + } + else { + *p_nb_iter = 1076.0; + *p_nb_bad = 456.0; + return -1.0000; + } + } + else { + *p_nb_iter = 1644.0; + *p_nb_bad = 639.0; + return -1.0000; + } + } + else { + *p_nb_iter = 2401.0; + *p_nb_bad = 713.0; + return -1.0000; + } + } + else if (p_features->merge_variance <= 281.9509) + { + *p_nb_iter = 1020.0; + *p_nb_bad = 262.0; + return 3.0000; + } + else { + *p_nb_iter = 1278.0; + *p_nb_bad = 594.0; + return -1.0000; + } + } + else { + *p_nb_iter = 10507.0; + *p_nb_bad = 2943.0; + return -1.0000; + } + } + else { + *p_nb_iter = 25229.0; + *p_nb_bad = 3060.0; + return -1.0000; + } +} + -static tree_predict predict_func_split[4] = { - tree_predict_split_depth_0, - tree_predict_split_depth_1, - tree_predict_split_depth_2, - tree_predict_split_depth_3 -}; /** * Allocate the structure and buffer @@ -626,6 +1400,22 @@ void fill_depth_matrix_8(uint8_t* matrix, vect_2D* cu, int8_t curr_depth, int8_t */ void ml_os_qt_gen(uint8_t* arr_depthMap, features_s* arr_features_cur, features_s* arr_features_up, uint8_t i_depth, int _level, uint8_t limited_flag) { + + + tree_predict predict_func_merge[4] = { + tree_predict_merge_depth_1, + tree_predict_merge_depth_2, + tree_predict_merge_depth_3, + tree_predict_merge_depth_4 + }; + + tree_predict predict_func_split[4] = { + tree_predict_split_depth_0, + tree_predict_split_depth_1, + tree_predict_split_depth_2, + tree_predict_split_depth_3 + }; + tree_predict prediction_function_merge = predict_func_merge[i_depth - 1]; tree_predict prediction_function_split = predict_func_split[i_depth - 1]; @@ -695,15 +1485,21 @@ void os_luma_qt_pred(ml_intra_ctu_pred_t* ml_intra_depth_ctu, uint8_t* luma_px, features_s features64; // Initialize to 0 all the features - features_init_array(arr_features_4, 256, qp);// , state->encoder_control->cfg.width* state->encoder_control->cfg.height); - features_init_array(arr_features_8, 64, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); - features_init_array(arr_features_16, 16, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); - features_init_array(arr_features_32, 4, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); - features_init_array(&features64, 1, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); + features_init_array(arr_features_4, 256, qp); + features_init_array(arr_features_8, 64, qp); + features_init_array(arr_features_16, 16, qp); + features_init_array(arr_features_32, 4, qp); + features_init_array(&features64, 1, qp); // Commpute the features for the current CTU for all depth - features_s* arr_features[5] = { &features64, arr_features_32, arr_features_16, arr_features_8, - arr_features_4 }; + features_s* arr_features[5]; + arr_features[0] = &features64; + arr_features[1] = arr_features_32; + arr_features[2] = arr_features_16; + arr_features[3] = arr_features_8; + arr_features[4] = arr_features_4; + + features_compute_all(arr_features, luma_px); // Generate the CDM for the current CTU diff --git a/src/ml_intra_cu_depth_pred.h b/src/ml_intra_cu_depth_pred.h index e072f784..10312dd9 100644 --- a/src/ml_intra_cu_depth_pred.h +++ b/src/ml_intra_cu_depth_pred.h @@ -82,8 +82,6 @@ typedef struct { typedef int (*tree_predict)(features_s*, double*, double*); -#include "ml_classifier_intra_depth_pred.h" - ml_intra_ctu_pred_t* kvz_init_ml_intra_depth_const(void); void kvz_end_ml_intra_depth_const(ml_intra_ctu_pred_t * ml_intra_depth_ctu); diff --git a/src/search.c b/src/search.c index 2a5347c1..741bc520 100644 --- a/src/search.c +++ b/src/search.c @@ -474,8 +474,6 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, // Assign correct depth limit constraint_t* constr = state->constraint; if(constr->ml_intra_depth_ctu) { - //pu_depth_intra.min = ctrl->cfg.pu_depth_intra.min; - //pu_depth_intra.max = ctrl->cfg.pu_depth_intra.max; pu_depth_intra.min = constr->ml_intra_depth_ctu->_mat_upper_depth[(x_local >> 3) + (y_local >> 3) * 8]; pu_depth_intra.max = constr->ml_intra_depth_ctu->_mat_lower_depth[(x_local >> 3) + (y_local >> 3) * 8]; }