@@ -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