Spaces:
Configuration error
Configuration error
Download utils.py from vikranth1111/cap_main_1: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/vikranth1111/cap_main_1/resolve/main/utils.py
- Command line
-
hf download hf://spaces/vikranth1111/cap_main_1/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/vikranth1111/cap_main_1/resolve/main/utils.py
652 Bytes
| # Code Source | |
| # https://datascience.stackexchange.com/questions/45165/how-to-get-accuracy-f1-precision-and-recall-for-a-keras-model | |
| from tensorflow.keras import backend as K | |
| def f1_metric(y_true, y_pred): #taken from old keras source code | |
| true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1))) | |
| possible_positives = K.sum(K.round(K.clip(y_true, 0, 1))) | |
| predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1))) | |
| precision = true_positives / (predicted_positives + K.epsilon()) | |
| recall = true_positives / (possible_positives + K.epsilon()) | |
| f1_val = 2*(precision*recall)/(precision+recall+K.epsilon()) | |
| return f1_val | |