From 0b454940f677fa059e073019ce77561cbfb16618 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Wed, 8 Nov 2023 12:10:50 +0000 Subject: [PATCH] Stats.dump, fix report if no data Fix #1458 --- returnn/util/basic.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/returnn/util/basic.py b/returnn/util/basic.py index 7e4828248a..8ff670a165 100644 --- a/returnn/util/basic.py +++ b/returnn/util/basic.py @@ -3868,11 +3868,15 @@ def dump(self, output_file_prefix=None, stream=None, stream_prefix=""): ) else: print(" %i seqs" % (self.num_seqs,), file=stream) - print(" Mean: %s" % (self.format_str(self.get_mean()),), file=stream) - print(" Std dev: %s" % (self.format_str(self.get_std_dev()),), file=stream) - print(" Min/max: %s / %s" % (self.format_str(self.min), self.format_str(self.max)), file=stream) - # print("Std dev (naive): %s" % numpy.sqrt(self.mean_sq - self.mean * self.mean), file=stream) + if self.num_seqs > 0: + print(" Mean: %s" % (self.format_str(self.get_mean()),), file=stream) + print(" Std dev: %s" % (self.format_str(self.get_std_dev()),), file=stream) + print(" Min/max: %s / %s" % (self.format_str(self.min), self.format_str(self.max)), file=stream) + # print("Std dev (naive): %s" % numpy.sqrt(self.mean_sq - self.mean * self.mean), file=stream) + else: + print(" (No data)", file=stream) if output_file_prefix: + assert self.num_seqs > 0, "cannot dump stats without any data" print(" Write mean/std-dev to %s.(mean|std_dev).txt." % (output_file_prefix,), file=stream) numpy.savetxt("%s.mean.txt" % output_file_prefix, self.get_mean()) numpy.savetxt("%s.std_dev.txt" % output_file_prefix, self.get_std_dev())