py
This commit is contained in:
53
compare.py
Normal file
53
compare.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import numpy as np
|
||||
import json
|
||||
datum = np.load('dump.npz.npy')
|
||||
|
||||
|
||||
with open('dump.json','r') as rr:
|
||||
js = json.load(rr)
|
||||
|
||||
|
||||
emb_dict = dict()
|
||||
for embed in js[1]:
|
||||
fr = embed['frame_number']
|
||||
vec = embed['vector']
|
||||
emb_dict[fr] = np.asarray(vec)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def cosine_sim(emb_in_1, emb_in_2):
|
||||
emb_in_1 = emb_in_1.astype(np.float32)
|
||||
emb_in_2 = emb_in_2.astype(np.float32)
|
||||
emb1_norm = np.linalg.norm(emb_in_1)
|
||||
emb2_norm = np.linalg.norm(emb_in_2)
|
||||
dot_prod = np.dot(emb_in_1, emb_in_2)
|
||||
similarity = dot_prod/(emb1_norm * emb2_norm)
|
||||
|
||||
return np.round(emb1_norm,5),np.round( emb2_norm,5), np.round( dot_prod,5),np.round( similarity,5)
|
||||
|
||||
|
||||
arr_in_deepstream = np.asarray([y for _,y in emb_dict.items()])
|
||||
|
||||
normed = np.divide(datum.T, np.linalg.norm(datum, axis=1)).T
|
||||
print('_________________________')
|
||||
|
||||
for fr, emb in emb_dict.items():
|
||||
emb1 = np.linalg.norm(emb)
|
||||
emb2 = np.linalg.norm(datum[fr])
|
||||
# print( cosine_sim(emb, datum[fr]))
|
||||
|
||||
|
||||
print('Deepstream and Actual norm')
|
||||
print(np.max(np.dot(arr_in_deepstream, normed.T),axis=1))
|
||||
|
||||
print('_________________________')
|
||||
for dat in datum:
|
||||
# print(cosine_sim(dat, datum[0]))
|
||||
pass
|
||||
|
||||
|
||||
#print(cosine_sim(datum[fr], datum[fr+1]))
|
||||
|
||||
#print(cosine_sim(emb_dict[fr], emb_dict[fr+1]))
|
||||
Reference in New Issue
Block a user