def Acc(y_t, y_p): """Computes accuracy for each label Argument: ground truth label Y (2D reshaped), prediction (2D reshaped) Returns: array of accuracy for each label""" a = BinaryAccuracy() #handles the fact that y_p is not given as a binary vector Acc_per_label = [] for i in range(8): a.update_state(y_t[:,i], y_p[:,i] ) acc = a.result().numpy() a.reset_states() Acc_per_label.append(acc) return Acc_per_label
def print_bin_predictions_match(y_test, yhat, binary=True): accuracy = BinaryAccuracy() if binary else SparseCategoricalAccuracy() for i in range(y_test.shape[0]): ix = colored(str(f'{i:02d} |'), 'grey') sep = colored('|', 'grey') y = int(y_test[i][0]) pred = f"{yhat[i][0]:.02f}" if binary else f"{np.argmax(yhat[i])}" accuracy.reset_states() accuracy.update_state(y, yhat[i]) true_pred = accuracy.result().numpy() == 1.0 color = "green" if true_pred else "red" pred = colored(pred, color) if i % 9 == 0: print(f"\n{ix} ", end='') print(f"{y} {sep} {pred} {sep} ", end="") print(colored("\n", "white"))