Clean version of machine learning constraint code. (ICIP paper)

This commit is contained in:
mercat 2019-09-11 15:49:56 +03:00
parent 309d3fa3b8
commit 1dac29d9a0
13 changed files with 862 additions and 34 deletions

View file

@ -138,6 +138,7 @@
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\constraint.c" />
<ClCompile Include="..\..\src\extras\crypto.cpp" /> <ClCompile Include="..\..\src\extras\crypto.cpp" />
<ClCompile Include="..\..\src\extras\libmd5.c" /> <ClCompile Include="..\..\src\extras\libmd5.c" />
<ClCompile Include="..\..\src\input_frame_buffer.c" /> <ClCompile Include="..\..\src\input_frame_buffer.c" />
@ -159,6 +160,7 @@
<ClCompile Include="..\..\src\imagelist.c" /> <ClCompile Include="..\..\src\imagelist.c" />
<ClCompile Include="..\..\src\inter.c" /> <ClCompile Include="..\..\src\inter.c" />
<ClCompile Include="..\..\src\intra.c" /> <ClCompile Include="..\..\src\intra.c" />
<ClCompile Include="..\..\src\ml_intra_cu_depth_pred.c" />
<ClCompile Include="..\..\src\nal.c" /> <ClCompile Include="..\..\src\nal.c" />
<ClCompile Include="..\..\src\rate_control.c" /> <ClCompile Include="..\..\src\rate_control.c" />
<ClCompile Include="..\..\src\rdo.c" /> <ClCompile Include="..\..\src\rdo.c" />
@ -199,6 +201,7 @@
<ClCompile Include="..\..\src\strategies\strategies-intra.c" /> <ClCompile Include="..\..\src\strategies\strategies-intra.c" />
<ClCompile Include="..\..\src\strategies\strategies-quant.c" /> <ClCompile Include="..\..\src\strategies\strategies-quant.c" />
<ClInclude Include="..\..\src\checkpoint.h" /> <ClInclude Include="..\..\src\checkpoint.h" />
<ClInclude Include="..\..\src\constraint.h" />
<ClInclude Include="..\..\src\cu.h" /> <ClInclude Include="..\..\src\cu.h" />
<ClInclude Include="..\..\src\extras\crypto.h" /> <ClInclude Include="..\..\src\extras\crypto.h" />
<ClInclude Include="..\..\src\extras\libmd5.h" /> <ClInclude Include="..\..\src\extras\libmd5.h" />
@ -259,6 +262,7 @@
<ClInclude Include="..\..\src\input_frame_buffer.h" /> <ClInclude Include="..\..\src\input_frame_buffer.h" />
<ClInclude Include="..\..\src\kvazaar_internal.h" /> <ClInclude Include="..\..\src\kvazaar_internal.h" />
<ClInclude Include="..\..\src\kvz_math.h" /> <ClInclude Include="..\..\src\kvz_math.h" />
<ClInclude Include="..\..\src\ml_intra_cu_depth_pred.h" />
<ClInclude Include="..\..\src\search_inter.h" /> <ClInclude Include="..\..\src\search_inter.h" />
<ClInclude Include="..\..\src\search_intra.h" /> <ClInclude Include="..\..\src\search_intra.h" />
<ClInclude Include="..\..\src\strategies\avx2\avx2_common_functions.h" /> <ClInclude Include="..\..\src\strategies\avx2\avx2_common_functions.h" />

View file

@ -52,6 +52,9 @@
<Filter Include="Threadwrapper"> <Filter Include="Threadwrapper">
<UniqueIdentifier>{f4abece9-e209-4817-a57e-c64ca7c5e05c}</UniqueIdentifier> <UniqueIdentifier>{f4abece9-e209-4817-a57e-c64ca7c5e05c}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Constraint">
<UniqueIdentifier>{895fc8cc-6f08-49a7-b377-b5c38a44d1b1}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\strategies\strategies-nal.c"> <ClCompile Include="..\..\src\strategies\strategies-nal.c">
@ -239,6 +242,12 @@
<ClCompile Include="..\..\src\threadwrapper\src\semaphore.cpp"> <ClCompile Include="..\..\src\threadwrapper\src\semaphore.cpp">
<Filter>Threadwrapper</Filter> <Filter>Threadwrapper</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\constraint.c">
<Filter>Constraint</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ml_intra_cu_depth_pred.c">
<Filter>Constraint</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\bitstream.h"> <ClInclude Include="..\..\src\bitstream.h">
@ -453,6 +462,12 @@
<ClInclude Include="..\..\src\threadwrapper\include\semaphore.h"> <ClInclude Include="..\..\src\threadwrapper\include\semaphore.h">
<Filter>Threadwrapper</Filter> <Filter>Threadwrapper</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\constraint.h">
<Filter>Constraint</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ml_intra_cu_depth_pred.h">
<Filter>Constraint</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<YASM Include="..\..\src\extras\x86inc.asm"> <YASM Include="..\..\src\extras\x86inc.asm">

View file

@ -53,6 +53,8 @@ libkvazaar_la_SOURCES = \
checkpoint.h \ checkpoint.h \
cfg.c \ cfg.c \
cfg.h \ cfg.h \
constraint.c \
constraint.h \
context.c \ context.c \
context.h \ context.h \
cu.c \ cu.c \
@ -85,6 +87,8 @@ libkvazaar_la_SOURCES = \
kvazaar.c \ kvazaar.c \
kvazaar_internal.h \ kvazaar_internal.h \
kvz_math.h \ kvz_math.h \
ml_intra_cu_depth_pred.c \
ml_intra_cu_depth_pred.h \
nal.c \ nal.c \
nal.h \ nal.h \
rate_control.c \ rate_control.c \

View file

@ -141,6 +141,8 @@ int kvz_config_init(kvz_config *cfg)
cfg->max_merge = 5; cfg->max_merge = 5;
cfg->early_skip = true; cfg->early_skip = true;
cfg->ml_pu_depth_intra = false;
return 1; return 1;
} }
@ -1260,6 +1262,9 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
else if OPT("early-skip") { else if OPT("early-skip") {
cfg->early_skip = (bool)atobool(value); cfg->early_skip = (bool)atobool(value);
} }
else if OPT("ml-pu-depth-intra") {
cfg->ml_pu_depth_intra = (bool)atobool(value);
}
else { else {
return 0; return 0;
} }

View file

@ -137,7 +137,8 @@ static const struct option long_options[] = {
{ "max-merge", required_argument, NULL, 0 }, { "max-merge", required_argument, NULL, 0 },
{ "early-skip", no_argument, NULL, 0 }, { "early-skip", no_argument, NULL, 0 },
{ "no-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" " - 0, 1, 2, 3: from 64x64 to 8x8\n"
" --pu-depth-intra <int>-<int> : Intra prediction units sizes [1-4]\n" " --pu-depth-intra <int>-<int> : Intra prediction units sizes [1-4]\n"
" - 0, 1, 2, 3, 4: from 64x64 to 4x4\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 <int> : Transform split depth for intra blocks [0]\n" " --tr-depth-intra <int> : Transform split depth for intra blocks [0]\n"
" --(no-)bipred : Bi-prediction [disabled]\n" " --(no-)bipred : Bi-prediction [disabled]\n"
" --cu-split-termination <string> : CU split search termination [zero]\n" " --cu-split-termination <string> : CU split search termination [zero]\n"

View file

@ -26,7 +26,7 @@
* \param state encoder state * \param state encoder state
* \return the pointer of constraint_t structure * \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; constraint_t* constr = NULL;
// Allocate the constraint_t strucutre // Allocate the constraint_t strucutre
constr = MALLOC(constraint_t, 1); 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 // Allocate the ml_intra_ctu_pred_t structure
constr->ml_intra_depth_ctu = NULL; 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(); 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 * \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; 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); kvz_end_ml_intra_depth_const(constr->ml_intra_depth_ctu);
} }

View file

@ -23,10 +23,10 @@
#include "ml_intra_cu_depth_pred.h" #include "ml_intra_cu_depth_pred.h"
#include "encoderstate.h" #include "encoderstate.h"
#define E_CONSTRAINT 1
/* Constraint structure: /* 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 { typedef struct {
// Structure used for the CTU depth prediction using Machine Learning in All Intra // Structure used for the CTU depth prediction using Machine Learning in All Intra
@ -34,7 +34,7 @@ typedef struct {
} constraint_t; } constraint_t;
void * kvz_init_const(encoder_state_t* state); void * kvz_init_constraint(encoder_state_t* state, encoder_control_t * const encoder);
void kvz_end_const(encoder_state_t* state); void kvz_constraint_free(encoder_state_t* state);
#endif #endif

View file

@ -708,7 +708,7 @@ void kvz_encoder_state_finalize(encoder_state_t * const state) {
if (!state->parent) { if (!state->parent) {
// End of the constraint structure // End of the constraint structure
kvz_end_const(state); kvz_constraint_free(state);
} }
kvz_bitstream_finalize(&state->stream); kvz_bitstream_finalize(&state->stream);

View file

@ -1164,6 +1164,7 @@ static void encoder_state_init_children(encoder_state_t * const state) {
kvz_threadqueue_free_job(&state->tqj_recon_done); kvz_threadqueue_free_job(&state->tqj_recon_done);
//Copy the constraint pointer //Copy the constraint pointer
// TODO: Try to do it in the if (state->is_leaf)
if (state->parent != NULL) { if (state->parent != NULL) {
state->constraint = state->parent->constraint; state->constraint = state->parent->constraint;
} }
@ -1342,7 +1343,7 @@ void kvz_encoder_prepare(encoder_state_t *state)
assert(state->frame->done); assert(state->frame->done);
// Intialization of the constraint structure // 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) { if (state->frame->num == -1) {

View file

@ -390,6 +390,9 @@ typedef struct kvz_config
/** \brief Enable Early Skip Mode Decision */ /** \brief Enable Early Skip Mode Decision */
uint8_t early_skip; uint8_t early_skip;
/** \brief Enable Machine learning CU depth prediction for Intra encoding. */
uint8_t ml_pu_depth_intra;
} kvz_config; } kvz_config;
/** /**

View file

@ -21,19 +21,793 @@
#include "ml_intra_cu_depth_pred.h" #include "ml_intra_cu_depth_pred.h"
static tree_predict predict_func_merge[4] = { int tree_predict_merge_depth_1(features_s* p_features, double* p_nb_iter, double* p_nb_bad)
tree_predict_merge_depth_1, {
tree_predict_merge_depth_2, if (p_features->merge_variance <= 140.3129)
tree_predict_merge_depth_3, {
tree_predict_merge_depth_4 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 * 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) 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_merge = predict_func_merge[i_depth - 1];
tree_predict prediction_function_split = predict_func_split[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; features_s features64;
// Initialize to 0 all the features // 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_4, 256, qp);
features_init_array(arr_features_8, 64, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); features_init_array(arr_features_8, 64, qp);
features_init_array(arr_features_16, 16, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); features_init_array(arr_features_16, 16, qp);
features_init_array(arr_features_32, 4, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); features_init_array(arr_features_32, 4, qp);
features_init_array(&features64, 1, qp);// state->encoder_control->cfg.width * state->encoder_control->cfg.height); features_init_array(&features64, 1, qp);
// Commpute the features for the current CTU for all depth // 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, features_s* arr_features[5];
arr_features_4 }; 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); features_compute_all(arr_features, luma_px);
// Generate the CDM for the current CTU // Generate the CDM for the current CTU

View file

@ -82,8 +82,6 @@ typedef struct {
typedef int (*tree_predict)(features_s*, double*, double*); 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); 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); void kvz_end_ml_intra_depth_const(ml_intra_ctu_pred_t * ml_intra_depth_ctu);

View file

@ -474,8 +474,6 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
// Assign correct depth limit // Assign correct depth limit
constraint_t* constr = state->constraint; constraint_t* constr = state->constraint;
if(constr->ml_intra_depth_ctu) { 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.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]; pu_depth_intra.max = constr->ml_intra_depth_ctu->_mat_lower_depth[(x_local >> 3) + (y_local >> 3) * 8];
} }