Skip to content

Commit

Permalink
Modifications to support benchmarking script
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbatista committed Nov 9, 2020
1 parent 71290d2 commit 52de02b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 0 additions & 2 deletions extract_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def main(config):

assert len(metadata) == len(df_parsed)



if config.save_files:

EXIF_REPORT_PATH = join(config.repr.directory, 'exif_metadata.csv')
Expand Down
1 change: 0 additions & 1 deletion extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
default=False,is_flag=True)



def main(config, list_of_files, frame_sampling, save_frames):
config = resolve_config(config_path=config, frame_sampling=frame_sampling, save_frames=save_frames)
reps = ReprStorage(os.path.join(config.repr.directory))
Expand Down
2 changes: 1 addition & 1 deletion winnow/feature_extraction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from .intermediate_cnn import *
from .frame_to_video import *
from .similarity_model import *
from .similarity_model import *
21 changes: 21 additions & 0 deletions winnow/feature_extraction/loading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pickle as pk
import matplotlib.pylab as plt
from sklearn.metrics import precision_recall_curve
from scipy.spatial.distance import cdist


def load_dataset(dataset):
Expand Down Expand Up @@ -137,6 +138,26 @@ def plot_pr_curve(pr_curve, title):
plt.show()


def calculate_similarities(queries, features):
"""
Function that generates video triplets from CC_WEB_VIDEO.
Args:
queries: indexes of the query videos
features: global features of the videos in CC_WEB_VIDEO
Returns:
similarities: the similarities of each query with the videos in the dataset
"""

features = features[0]
similarities = dict()
dist = np.nan_to_num(cdist(features[queries], features, metric='euclidean'))
for i, v in enumerate(queries):
sim = np.round(1 - dist[i] / dist.max(), decimals=6)
similarities[i + 1] = [(s, sim[s]) for s in sim.argsort()[::-1] if not np.isnan(sim[s])]
return similarities


def evaluate(ground_truth,
similarities,
positive_labels='ESLMV',
Expand Down
7 changes: 6 additions & 1 deletion winnow/feature_extraction/similarity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def predict(self, file_feature_dict):
# values in the same order
keys, features = zip(*file_feature_dict.items())
features = np.array([tensor[0] for tensor in features])
embeddings = self.predict_from_features(features)

return dict(zip(keys, embeddings))

def predict_from_features(self, features):

# Create model
if self.model is None:
Expand All @@ -36,4 +41,4 @@ def predict(self, file_feature_dict):

embeddings = self.model.embeddings(features)
embeddings = np.nan_to_num(embeddings)
return dict(zip(keys, embeddings))
return embeddings

0 comments on commit 52de02b

Please sign in to comment.