As is clear from the relevant Keras docs, tpr
& tnr
are not part of the native Keras metrics; there is a relevant Github thread, but the issue is still open.
But for the binary case you seem to work on, it is straightforward to get the required quantities from scikit-learn (you'll need to convert the model outcomes to binary labels, i.e. not probabilities); adapting the example from the docs:
from sklearn.metrics import confusion_matrix
y_true = [0, 1, 0, 1]
y_pred = [1, 1, 1, 0]
cm = confusion_matrix(y_true, y_pred) # careful with the order of arguments!
tn, fp, fn, tp = cm.ravel()
(tn, fp, fn, tp)
# (0, 2, 1, 1)
Having obtained these quantities, it is now straightforward to compute TPR & TNR (see the definitions in Wikipedia):
TPR = tp/(tp+fn)
TPR
# 0.5
TNR = tn/(tn+fp)
TNR
# 0.0
The multi-class case is a bit more complicated - see my answer in How to get precision, recall and f-measure from confusion matrix in Python.