Closed
Description
I came across the problem where
output_scores[similarity_fn_name] = {
"accuracy": acc,
"accuracy_threshold": acc_threshold,
"f1": f1,
"f1_threshold": f1_threshold,
"precision": precision,
"recall": recall,
"ap": ap,
}
is returning outputs in np.float32()
and np.float64()
which cause problems during model saving, as the json/encoder.py
sees those types as not JSON serializable
.
By changing the code snippet to
output_scores[similarity_fn_name] = {
"accuracy": acc.item(),
"accuracy_threshold": acc_threshold.item(),
"f1": f1.item(),
"f1_threshold": f1_threshold.item(),
"precision": precision,
"recall": recall.item(),
"ap": ap.item(),
}
the elements get copied to a standard Python scalar each (note: precision
already is) and then behave like expected during saving.