Add relaxed max partition prediciton mode

Introduce a new metric to determine the max partition prediction
using NN.
The new metric performs on cumulative probabilities. Starting from
the largest size, the prediction is where the cumulative prob
exceeds 0.2.
This metric often produces a relaxed(bigger) max part prediction
compared to just picking the size with the highest score.
This mode is enabled on videos >= 480p but < 720p.

midres: speed up 5.7%, BDRate 0.052%

STATS_CHANGED

Change-Id: I5d6d5ef9c769debb38e7f4909ffdacabde1784b7
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 61fa9c5..71f848f 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -3651,7 +3651,7 @@
   AV1_COMMON *const cm = &cpi->common;
 
   return !frame_is_intra_only(cm) &&
-         cpi->sf.auto_max_partition_based_on_simple_motion &&
+         cpi->sf.auto_max_partition_based_on_simple_motion != NOT_IN_USE &&
          sb_size == BLOCK_128X128 && is_full_sb(cm, mi_row, mi_col, sb_size) &&
          cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index] !=
              OVERLAY_UPDATE &&
@@ -3759,20 +3759,31 @@
 }
 
 #define MAX_NUM_CLASSES 4
-static BLOCK_SIZE predict_max_partition(float *features) {
+static BLOCK_SIZE predict_max_partition(
+    const MAX_PART_PRED_MODE max_part_pred_mode, const float *features) {
   float scores[MAX_NUM_CLASSES] = { 0.0f }, probs[MAX_NUM_CLASSES] = { 0.0f };
   const NN_CONFIG *nn_config = &av1_max_part_pred_nn_config;
 
+  assert(max_part_pred_mode != NOT_IN_USE);
+
   aom_clear_system_state();
   av1_nn_predict(features, nn_config, scores);
   av1_nn_softmax(scores, probs, MAX_NUM_CLASSES);
 
-  int result = 0;
-  float max_prob = probs[0];
-  for (int i = 1; i < MAX_NUM_CLASSES; ++i) {
-    if (probs[i] > max_prob) {
-      max_prob = probs[i];
-      result = i;
+  int result = MAX_NUM_CLASSES - 1;
+  if (max_part_pred_mode == DIRECT_PRED) {
+    result = 0;
+    float max_prob = probs[0];
+    for (int i = 1; i < MAX_NUM_CLASSES; ++i) {
+      if (probs[i] > max_prob) {
+        max_prob = probs[i];
+        result = i;
+      }
+    }
+  } else if (max_part_pred_mode == RELAXED_PRED) {
+    for (result = MAX_NUM_CLASSES - 1; result >= 0; --result) {
+      if (result < MAX_NUM_CLASSES - 1) probs[result] += probs[result + 1];
+      if (probs[result] > 0.2) break;
     }
   }
 
@@ -5709,7 +5720,10 @@
 
         get_max_min_partition_features(cpi, tile_info, x, mi_row, mi_col,
                                        features);
-        max_sq_size = AOMMIN(predict_max_partition(features), max_sq_size);
+        max_sq_size = AOMMIN(
+            predict_max_partition(
+                cpi->sf.auto_max_partition_based_on_simple_motion, features),
+            max_sq_size);
       }
 
       min_sq_size = AOMMIN(min_sq_size, max_sq_size);
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 2923f09..ff5c775 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -98,9 +98,13 @@
 
   if (is_480p_or_larger) {
     sf->use_square_partition_only_threshold = BLOCK_128X128;
+    if (is_720p_or_larger)
+      sf->auto_max_partition_based_on_simple_motion = NOT_IN_USE;
+    else
+      sf->auto_max_partition_based_on_simple_motion = RELAXED_PRED;
   } else {
     sf->use_square_partition_only_threshold = BLOCK_64X64;
-    sf->auto_max_partition_based_on_simple_motion = 1;
+    sf->auto_max_partition_based_on_simple_motion = DIRECT_PRED;
   }
 
   // TODO(huisu@google.com): train models for 720P and above.
@@ -676,7 +680,7 @@
   sf->less_rectangular_check_level = 0;
   sf->use_square_partition_only_threshold = BLOCK_128X128;
   sf->prune_ref_frame_for_rect_partitions = 0;
-  sf->auto_max_partition_based_on_simple_motion = 0;
+  sf->auto_max_partition_based_on_simple_motion = NOT_IN_USE;
   sf->auto_min_partition_based_on_simple_motion = 0;
   sf->rd_auto_partition_min_limit = BLOCK_4X4;
   sf->default_max_partition_size = BLOCK_LARGEST;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 7663be6..2d56c58 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -198,6 +198,8 @@
   FULL_PEL
 } UENUM1BYTE(SUBPEL_FORCE_STOP);
 
+enum { NOT_IN_USE, DIRECT_PRED, RELAXED_PRED } UENUM1BYTE(MAX_PART_PRED_MODE);
+
 typedef struct MV_SPEED_FEATURES {
   // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
   SEARCH_METHODS search_method;
@@ -402,7 +404,7 @@
   // Sets min and max square partition levels for this superblock based on
   // motion vector and prediction error distribution produced from 16x16
   // simple motion search
-  int auto_max_partition_based_on_simple_motion;
+  MAX_PART_PRED_MODE auto_max_partition_based_on_simple_motion;
   int auto_min_partition_based_on_simple_motion;
 
   // Ensures the rd based auto partition search will always