tflearn icon indicating copy to clipboard operation
tflearn copied to clipboard

TensorBoard: how to plot custom variable?

Open kulsemig opened this issue 9 years ago • 0 comments

How can i plot changes of some custom variable at each epoch with tflearn and tensorboard? I found some way how i can show my custom variable with callbacks in console. But i want visualize that changes using tensorboard.

NR = 3500 #Amount of first class data
NS = 3500 #Amount of second class data

class CustomCallback(tflearn.callbacks.Callback):
    def __init__(self):
        pass
    def on_epoch_end(self, training_state):
        TP = 0
        TN = 0
        FP = 0
        FN = 0
        predictions = model.predict(X)
        for prediction, actual in zip(predictions, Y):
            predicted_class = np.argmax(prediction)
            actual_class = np.argmax(actual)
            if predicted_class == 1:
                if actual_class == 1:
                    TP+=1
                else:
                    FP+=1
            else:
                if actual_class == 0:
                    TN+=1
                else:
                    FN+=1
        Metric = (TP / NR) - (FP / NS)
        print ("Metric: " + str(Metric))
        print("--")

callback = CustomCallback()

model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(X, Y, n_epoch=3, show_metric=True, callbacks=callback)

Like this example

kulsemig avatar Aug 20 '17 09:08 kulsemig