ensure ksims and kscores are correct size
Browse files
app.py
CHANGED
|
@@ -57,11 +57,12 @@ def knn_get_score(knn, k, cat, vec):
|
|
| 57 |
sortinds = np.flip(np.argsort(cos_sim_table, axis=1), axis=1)
|
| 58 |
if debug: st.write('sortinds.shape', sortinds.shape)
|
| 59 |
# Get corresponding scores for the sorted vectors
|
| 60 |
-
kscores = scores[sortinds][:k]
|
| 61 |
if debug: st.write('kscores.shape', kscores.shape)
|
| 62 |
# Get actual sorted similiarity scores
|
| 63 |
# (line copied from clip_retrieval_knn.py even though sortinds.shape[0] == 1 here)
|
| 64 |
ksims = cos_sim_table[np.expand_dims(np.arange(sortinds.shape[0]), axis=1), sortinds]
|
|
|
|
| 65 |
if debug: st.write('ksims.shape', ksims.shape)
|
| 66 |
# Apply normalization after exponential formula
|
| 67 |
ksims = softmax(10**ksims)
|
|
|
|
| 57 |
sortinds = np.flip(np.argsort(cos_sim_table, axis=1), axis=1)
|
| 58 |
if debug: st.write('sortinds.shape', sortinds.shape)
|
| 59 |
# Get corresponding scores for the sorted vectors
|
| 60 |
+
kscores = scores[sortinds][:,:k]
|
| 61 |
if debug: st.write('kscores.shape', kscores.shape)
|
| 62 |
# Get actual sorted similiarity scores
|
| 63 |
# (line copied from clip_retrieval_knn.py even though sortinds.shape[0] == 1 here)
|
| 64 |
ksims = cos_sim_table[np.expand_dims(np.arange(sortinds.shape[0]), axis=1), sortinds]
|
| 65 |
+
ksims = ksims[:,:k]
|
| 66 |
if debug: st.write('ksims.shape', ksims.shape)
|
| 67 |
# Apply normalization after exponential formula
|
| 68 |
ksims = softmax(10**ksims)
|