This module contains all the code for defining the various approaches
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
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'])
from nbdev.export import notebook2script
notebook2script()