narugo commited on
Commit
06cef48
·
1 Parent(s): dae87e0

dev(narugo): add percentile value

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -36,6 +36,17 @@ def _get_mark_table(model):
36
  return x, y
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
39
  def _fn_predict(image, model):
40
  scores = classify_predict_score(
41
  image=image,
@@ -44,7 +55,7 @@ def _fn_predict(image, model):
44
  )
45
  weighted_mean = sum(i * scores[label] for i, label in enumerate(LABELS))
46
  x, y = _get_mark_table(model)
47
- percentile = y[np.searchsorted(x, np.clip(weighted_mean, a_min=0.0, a_max=6.0))]
48
  return weighted_mean, percentile, scores
49
 
50
 
 
36
  return x, y
37
 
38
 
39
+ def _get_percentile(x, y, v):
40
+ idx = np.searchsorted(x, np.clip(v, a_min=0.0, a_max=6.0))
41
+ if idx < x.shape[0] - 1:
42
+ x0, y0 = x[idx], y[idx]
43
+ x1, y1 = x[idx + 1], y[idx + 1]
44
+ return np.clip((v - x0) / (x1 - x0) * (y1 - y0) + y0, a_min=0.0, a_max=1.0)
45
+
46
+ else:
47
+ return y[idx]
48
+
49
+
50
  def _fn_predict(image, model):
51
  scores = classify_predict_score(
52
  image=image,
 
55
  )
56
  weighted_mean = sum(i * scores[label] for i, label in enumerate(LABELS))
57
  x, y = _get_mark_table(model)
58
+ percentile = _get_percentile(x, y, weighted_mean)
59
  return weighted_mean, percentile, scores
60
 
61