TeamHG-Memex / tensorboard_logger

Log TensorBoard events without touching TensorFlow
MIT License
630 stars 50 forks source link

Scalar names not propogating properly #8

Closed elbamos closed 7 years ago

elbamos commented 7 years ago

My code has a list of classes, and at the end of every epoch its supposed to go through the list and log scalars, tagging them "recall_classname", "precision_classname" and so forth.

What's showing up in tensorboard isn't those names though, its "recall", "recall/1", "recall/2", and so forth, then finally "recall.", etc.

What am I doing wrong?

The code is:

classestouse = [2,3,4,9,12,13,16,17]
classes = ["none", "comma", "period", "colon", "questionmark", "semicolon", "and", "exclamationpoint"]

def on_end_epoch(state):
    logger.log_value("loss_mean", avgmeter.value()[1], state['epoch'])
    logger.log_value("loss_sd", avgmeter.value()[1], state['epoch'])
    avgacc = sum(classmeter.value()) / len(classmeter.value())
    logger.log_value("loss_avgacc", avgacc, state['epoch'])
    state['iterator'].set_postfix(accuracy = avgacc, loss = avgmeter.value()[0], losssd = avgmeter.value()[1])
    confusion = confusionmeter.value()
    if state['train']:
        for i, v in zip(classestouse, classes):
            correct = confusion[i][i]
            groundtruth = confusion[i].sum()
            predicted = confusion[:, i].sum()
            recall = correct / groundtruth
            precision = correct / predicted
            v = punctypes.vocab.itos[i]
            logger.log_value("recall_%s" % (v), recall, state['epoch'])
            logger.log_value("precision_%s" % (v), precision, state['epoch'])
            logger.log_value('accuracy_%s' % (v), classmeter.value(i), state['epoch'])

(BTW - yes, I know those aren't the correct formula for precision and recall.)

elbamos commented 7 years ago

Found my own bug as soon as I was done posting this... Sorry!

lopuhin commented 7 years ago

Glad you solved it! 👍