import tensorflow as tf
import numpy as np
N_TRUE_P = 0
N_PRED_P = 0
def reset_running_variables():
""" Resets the previous values of running variables to zero """
global N_TRUE_P, N_PRED_P
N_TRUE_P = 0
N_PRED_P = 0
def update_running_variables(labs, preds):
global N_TRUE_P, N_PRED_P
N_TRUE_P += ((labs * preds) > 0).sum()
N_PRED_P += (preds > 0).sum()
def calculate_precision():
global N_TRUE_P, N_PRED_P
return float (N_TRUE_P) / N_PRED_P
if __name__ == '__main__':
labels = np.array([[1,1,1,0],
[1,1,1,0],
[1,1,1,0],
[1,1,1,0]], dtype=np.uint8)
predictions = np.array([[1,0,0,0],
[1,1,0,0],
[1,1,1,0],
[0,1,1,1]], dtype=np.uint8)
n_batches &#