pytorch/tnt

printMeter works incorrectly due to wrong indent

huhk-sysu opened this issue · 2 comments

MeterLogger.printMeter can't print desire information because of a logical error caused by wrong indent.

Currently it can only print the default 'loss' meter.

Below is the source of the function.

(starts from line 123 in meterlogger.py

def print_meter(self, mode, iepoch, ibatch=1, totalbatch=1, meterlist=None):
    pstr = "%s:\t[%d][%d/%d] \t"
    tval = []
    tval.extend([mode, iepoch, ibatch, totalbatch])
    if meterlist is None:
        meterlist = self.meter.keys()
        for meter in meterlist:
            if meter in ['confusion', 'histogram', 'image']:
                continue
            if meter == 'accuracy':
                pstr += "Acc@1 %.2f%% \t Acc@" + str(self.topk) + " %.2f%% \t"
                tval.extend([self.meter[meter].value()[0], self.meter[meter].value()[1]])
            elif meter == 'map':
                pstr += "mAP %.3f \t"
                tval.extend([self.meter[meter].value()])
            elif meter == 'auc':
                pstr += "AUC %.3f \t"
                tval.extend([self.meter[meter].value()])
            else:
                pstr += meter + " %.3f (%.3f)\t"
                tval.extend([self.meter[meter].val, self.meter[meter].mean])
                pstr += " %.2fs/its\t"
                tval.extend([self.timer.value()])
                print(pstr % tuple(tval))

I think the error comes from commit 7b1dc6c when formatting.

image

That sounds reasonable to me. Looks like L104-120 should be unindented once, and L121 unindented twice. Also: #83

seems to be fixed now by #83