This module contains all the code for defining the various approaches

flatten_dict[source]

flatten_dict(d_in, d_out, parent_key)

gen_extracted_features[source]

gen_extracted_features(vid_ds, mdl, fps, ftk)

gen_tfidfs[source]

gen_tfidfs(vid_ds_features, vw, codebook, df, ftk)

gen_bovw_similarity[source]

gen_bovw_similarity(vid_ds, vid_ds_features, mdl, codebook, vw, ftk)

fuzzy_LCS[source]

fuzzy_LCS(X, Y, m, n, sim_func, codebook, df, vw, mdl_frame_threshold=0.0)

Some examples showing the differences between f-LCS and w-LCS

This example shows an example where there is a lot of overlap causes f-LCS similarity to be high, but since the overlap is not toward the end, the w-LCS similarity is lower.

X = [1, 2, 3, 4, 5]
Y = [3, 4, 5, 6, 7, 8]
test_sim_func = lambda *args: int(args[0] == args[1])
lcs, weighted_lcs = fuzzy_LCS(X, Y, len(X), len(Y), test_sim_func, None, None, None)
lcs, weighted_lcs

This example shows that if the overlap is towards the end of the two sequences, w-LCS will have a higher similarity than f-LCS

X = [1, 2, 3, 4, 5]
Y = [11, 12, 3, 4, 5]
lcs, weighted_lcs = fuzzy_LCS(X, Y, len(X), len(Y), test_sim_func, None, None, None)
lcs, weighted_lcs

gen_lcs_similarity[source]

gen_lcs_similarity(vid_ds, vid_ds_features, sim_func, mdl, codebook, df, vw, ftk)

fix_sims[source]

fix_sims(vid_sims, vid_ds)

sort_rankings[source]

sort_rankings(vid_sims)

approach[source]

approach(vid_ds, vid_ds_features, bovw_vid_ds_sims, lcs_vid_ds_sims, mdl, sim_func, codebook, df, vw, fps=30, ftk=1)

path = Path("/tf/data/datasets/validation_set")
vid_ds = VideoDataset.from_path(path).label_from_paths()
vid_ds.get_labels()
fps = 30
ftk = 1
vw = 1_000
model_01 = 'M01'
simclr = SimCLRModel.load_from_checkpoint(checkpoint_path = str('/tf/data/models/simclr/checkpointepoch=98.ckpt')).eval()
M01 = SimCLRExtractor(simclr)

fname = f'/tf/data/models/codebooks/M01/cookbook_M01_{vw}vw.model'
codebook_01 = pickle.load(open(fname, 'rb'))
vid_ds_features = gen_extracted_features(vid_ds, M01, fps, ftk)
df, bovw_vid_ds_sims = gen_bovw_similarity(vid_ds, vid_ds_features, M01, codebook_01, vw, ftk)
lcs_vid_ds_sims = gen_lcs_similarity(vid_ds, vid_ds_features, simclr_frame_sim, M01, codebook_01, df, vw, ftk)
# vid_ds_features = gen_extracted_features(vid_ds, M01, fps, ftk)
# df, vid_ds_sims = gen_similarity(vid_ds, vid_ds_features, M01, codebook_01, vw, ftk)
rankings_01 = approach(
    vid_ds, vid_ds_features, bovw_vid_ds_sims, lcs_vid_ds_sims, M01, simclr_frame_sim,
    codebook_01, df, vw, fps = fps, ftk = ftk,
)
rankings_01['weighted_lcs']
evals = evaluate(rankings_01['lcs'])

compute_sims[source]

compute_sims(q_vid, vid_ds, model, codebook, vw, fps, ftk)

from nbdev.export import notebook2script
notebook2script()