Commit 3916082c authored by Yue Chen's avatar Yue Chen

entropy_stats: add python script for aggregating multi counts.stt

A python script is provided to accumulate stats from counts.stt
files generated from multiple encoding examples. Command line:
python ../../tools/aggregate_entropy_stats.py [dir of stats files]
 [keyword of filenames] [filename of final stats]

Plus cosmetics on output format of optimized prob tables. The comma
after the last element of each dimension is removed, i.e.,
before: {
          { 128, 128, 128, },
          { 128, 128, 128, },
        }
after:  {
          { 128, 128, 128 },
          { 128, 128, 128 }
        }.
The reason is to avoid moving '}' to a second line after applying
clang-format.

Change-Id: I3b764f4c89b7aefbaf48ac00b8c83713caf75a5d
parent ebced376
#!/usr/bin/env python
## Copyright (c) 2017, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
"""Aggregate multiple entropy stats output which is written in 32-bit int.
python ./aggregate_entropy_stats.py [dir of stats files] [keyword of filenames]
[filename of final stats]
"""
__author__ = "yuec@google.com"
import os
import sys
import numpy as np
def main():
dir = sys.argv[1]
sum = []
for fn in os.listdir(dir):
if sys.argv[2] in fn:
stats = np.fromfile(dir + fn, dtype=np.int32)
if len(sum) == 0:
sum = stats
else:
sum = np.add(sum, stats)
if len(sum) == 0:
print("No stats file is found. Double-check directory and keyword?")
else:
sum.tofile(dir+sys.argv[3])
if __name__ == '__main__':
main()
......@@ -131,7 +131,10 @@ static int parse_stats(aom_count_type **ct_ptr, FILE *const probsfile, int tabs,
}
if (tabs > 0) fprintf(probsfile, "%*c", tabs * SPACES_PER_TAB, ' ');
for (int k = 0; k < total_modes - 1; ++k) {
fprintf(probsfile, " %3d,", probs[k]);
if (k == total_modes - 2)
fprintf(probsfile, " %3d ", probs[k]);
else
fprintf(probsfile, " %3d,", probs[k]);
fprintf(logfile, "%d ", counts1d[k]);
}
fprintf(logfile, "%d\n", counts1d[total_modes - 1]);
......@@ -139,7 +142,13 @@ static int parse_stats(aom_count_type **ct_ptr, FILE *const probsfile, int tabs,
assert(cts_each_dim[1] == 2);
for (int k = 0; k < cts_each_dim[0]; ++k) {
fprintf(probsfile, " %3d,", get_binary_prob((*ct_ptr)[0], (*ct_ptr)[1]));
if (k == cts_each_dim[0] - 1) {
fprintf(probsfile, " %3d ",
get_binary_prob((*ct_ptr)[0], (*ct_ptr)[1]));
} else {
fprintf(probsfile, " %3d,",
get_binary_prob((*ct_ptr)[0], (*ct_ptr)[1]));
}
fprintf(logfile, "%d %d\n", (*ct_ptr)[0], (*ct_ptr)[1]);
(*ct_ptr) += 2;
}
......@@ -158,9 +167,15 @@ static int parse_stats(aom_count_type **ct_ptr, FILE *const probsfile, int tabs,
return 1;
}
if (dim_of_cts == 2 || (dim_of_cts == 3 && flatten_last_dim)) {
fprintf(probsfile, "},\n");
if (k == cts_each_dim[0] - 1)
fprintf(probsfile, "}\n");
else
fprintf(probsfile, "},\n");
} else {
fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
if (k == cts_each_dim[0] - 1)
fprintf(probsfile, "%*c}\n", tabs * SPACES_PER_TAB, ' ');
else
fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment