Skip to content

Commit fd843ec

Browse files
author
rbodo
committed
Improved logging the ANN and SNN accuracy during a run.
1 parent eb17118 commit fd843ec

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

snntoolbox/bin/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@ def update_setup(config_filepath):
401401
assert os.path.isfile(py_filepath), \
402402
"File {} not found.".format(py_filepath)
403403
else:
404-
print("For the specified input model library {}, no test is "
405-
"implemented to check if input model files exist in the "
406-
"specified working directory!".format(model_lib))
404+
pass
405+
# print("For the specified input model library {}, no test is "
406+
# "implemented to check if input model files exist in the "
407+
# "specified working directory!".format(model_lib))
407408

408409
# Set default path if user did not specify it.
409410
if config.get('paths', 'dataset_path') == '':

snntoolbox/simulation/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ def run(self, x_test=None, y_test=None, dataflow=None, **kwargs):
531531
path_acc = os.path.join(log_dir, 'accuracy.txt')
532532
if os.path.isfile(path_acc):
533533
os.remove(path_acc)
534+
with open(path_acc, str('a')) as f_acc:
535+
f_acc.write(str("# samples | SNN top-1 | top-{0} | ANN top-1 | "
536+
"top-{0}\n".format(self.top_k)))
534537

535538
self.init_log_vars()
536539

@@ -632,9 +635,6 @@ def run(self, x_test=None, y_test=None, dataflow=None, **kwargs):
632635
batch_idx + 1, num_batches, (batch_idx + 1) / num_batches))
633636
print("Moving accuracy of SNN (top-1, top-{}): {:.2%}, {:.2%}."
634637
"".format(self.top_k, top1acc_moving, top5acc_moving))
635-
with open(path_acc, str('a')) as f_acc:
636-
f_acc.write(str("{} {:.2%} {:.2%}\n".format(
637-
num_samples_seen, top1acc_moving, top5acc_moving)))
638638

639639
# Evaluate ANN on the same batch as SNN for a direct comparison.
640640
score = self.parsed_model.evaluate(
@@ -647,6 +647,11 @@ def run(self, x_test=None, y_test=None, dataflow=None, **kwargs):
647647
"\n".format(self.top_k, 1 - self.top1err_ann,
648648
1 - self.top5err_ann))
649649

650+
with open(path_acc, str('a')) as f_acc:
651+
f_acc.write(str("{} {:.2%} {:.2%} {:.2%} {:.2%}\n".format(
652+
num_samples_seen, top1acc_moving, top5acc_moving,
653+
1 - self.top1err_ann, 1 - self.top5err_ann)))
654+
650655
# Plot input image.
651656
if 'input_image' in self._plot_keys:
652657
snn_plt.plot_input_image(x_b_l[0], int(truth_b[0]), log_dir,

0 commit comments

Comments
 (0)