From 8cfe3c3937993f53c785f15eebf19b7119b82ae3 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Tue, 22 Jun 2021 11:36:33 +0800 Subject: [PATCH] fix(lar): update --verbose to --model-info GitOrigin-RevId: 6d928ee46bc1bc45efb75d586403e7a7e53d687f --- sdk/load-and-run/src/mgblar.cpp | 12 ++++++------ sdk/load-and-run/src/text_table.h | 30 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/sdk/load-and-run/src/mgblar.cpp b/sdk/load-and-run/src/mgblar.cpp index 86d2332c..d4138dcc 100644 --- a/sdk/load-and-run/src/mgblar.cpp +++ b/sdk/load-and-run/src/mgblar.cpp @@ -92,7 +92,7 @@ R"__usage__( param.json --data bbox:bbox.npy@batchid:b.npy --data rect:[0,0,227,227]; batchid:0,1,2,3. --io-dump or --bin-io-dump should be enabled at the same time. - --verbose + --model-info Format and display model input/output tensor info. --io-dump | --bin-io-dump Dump input/output values of all internal variables to output file or @@ -529,7 +529,7 @@ struct Args { COprArgs c_opr_args; - bool show_verbose = false; + bool display_model_info = false; bool disable_assert_throw = false; bool share_param_mem = false; #if MGB_ENABLE_FASTRUN @@ -710,7 +710,7 @@ void run_test_st(Args &env) { ComputingGraph::OutputSpec out_spec; std::string output_names; - if (env.show_verbose) { + if (env.display_model_info) { format_and_print("Original Model Info", env); } @@ -1026,7 +1026,7 @@ void run_test_st(Args &env) { } #endif - if (env.show_verbose) { + if (env.display_model_info) { format_and_print("Runtime Model Info", env); } } @@ -1259,9 +1259,9 @@ Args Args::from_argv(int argc, char **argv) { } continue; } - if (!strcmp(argv[i], "--verbose")) { + if (!strcmp(argv[i], "--model-info")) { ++i; - ret.show_verbose = true; + ret.display_model_info = true; continue; } if (!strcmp(argv[i], "--io-dump")) { diff --git a/sdk/load-and-run/src/text_table.h b/sdk/load-and-run/src/text_table.h index ce7a172a..a0f08fec 100644 --- a/sdk/load-and-run/src/text_table.h +++ b/sdk/load-and-run/src/text_table.h @@ -56,16 +56,24 @@ public: template TextTable& add(const T& value) { - if constexpr (std::is_floating_point::value) { - std::stringstream ss; - ss << std::setiosflags(std::ios::fixed) << std::setprecision(2); - ss << value; - m_row.values.emplace_back(ss.str()); - } else if constexpr (std::is_integral::value) { - m_row.values.emplace_back(std::to_string(value)); + m_row.values.emplace_back(value); + if (m_cols_max_w.size() < m_row.values.size()) { + m_cols_max_w.emplace_back(m_row.values.back().length()); } else { - m_row.values.emplace_back(value); + mgb_assert(m_row.values.size() >= 1); + size_t i = m_row.values.size() - 1; + m_cols_max_w[i] = + std::max(m_cols_max_w[i], m_row.values.back().length()); } + return *this; + } + + template ::value, bool>::type = 0> + TextTable& add(const T& value) { + std::stringstream ss; + ss << std::setiosflags(std::ios::fixed) << std::setprecision(2); + ss << value; + m_row.values.emplace_back(ss.str()); if (m_cols_max_w.size() < m_row.values.size()) { m_cols_max_w.emplace_back(m_row.values.back().length()); } else { @@ -77,6 +85,12 @@ public: return *this; } + template ::value, bool>::type = 0> + TextTable& add(const T& value) { + m_row.values.emplace_back(std::to_string(value)); + return *this; + } + void eor() { m_rows.emplace_back(m_row); adjuster_last_row();