This module contains all the necessary functions for extracting and organizing features from videos.
model = SimCLRModel.load_from_checkpoint(checkpoint_path='/tf/data/models/simclr/checkpointepoch=98.ckpt').eval()
simclr_extractor = SimCLRExtractor(model)
features_0 = simclr_extractor.extract(sampled_imgs[7]).detach().numpy()
features_1 = simclr_extractor.extract(sampled_imgs[9]).detach().numpy()
imgs = get_rand_imgs(video_paths[0], 30_000, n = 100)
fname = f'/tf/data/models/features/M00/15000n_features.pkl'
features_list = pickle.load(open(fname, 'rb'))
len(features_list)
vwords = 1_000
codebook = gen_vcodebook(sampled_imgs, extractor, vwords)
labels = codebook.predict(features)
hist = np.histogram(labels, bins = range(vwords + 1))
plt.bar(range(vwords), hist[0])
df = get_df(imgs, extractor, codebook, vwords)
plt.bar(range(vwords), df)
plt.show()
vid = Video(video_paths[3])
features = extract_features(vid, extractor, fps = 30, frames_to_keep = 1)
bovw = new_get_bovw(features, codebook, vwords, frames_to_keep = 2)
plt.bar(range(vwords), hist)
plt.show()
hist
tf_idf_pix2 = calc_tf_idf(hist, df)
hist2, bovw2 = get_bovw(video_paths[2], extractor, codebook)
tf_idf_pix1 = calc_tf_idf(hist2, df)
np.dot(tf_idf_pix1, tf_idf_pix2) / (np.linalg.norm(tf_idf_pix1) * np.linalg.norm(tf_idf_pix2))