-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from duggalsu/benchmark_es
Add ElasticSearch benchmarking
- Loading branch information
Showing
9 changed files
with
342 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ credentials.json | |
|
||
# pyinstrument | ||
*.json | ||
|
||
# locust | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import unittest | ||
from unittest.case import skip | ||
import pprint | ||
from core.store.es_vec import ES | ||
from core.config import StoreConfig, StoreParameters | ||
from core.models.media import MediaType | ||
from core.operators import vid_vec_rep_resnet | ||
from datetime import datetime | ||
|
||
pp = pprint.PrettyPrinter(indent=4) | ||
''' | ||
# Get indexing stats | ||
curl -X GET "http://es:9200/_stats/indexing?pretty" | ||
# Check how many documents have been indexed | ||
curl -X GET "http://es:9200/_cat/indices?v" | ||
# Delete all the documents in an index | ||
curl -X POST "http://es:9200/video/_delete_by_query" -H 'Content-Type: application/json' -d'{"query":{"match_all":{}}}' | ||
''' | ||
|
||
|
||
class TestVideoES(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls) -> None: | ||
param_dict = { | ||
"host_name": "es", | ||
"text_index_name": "text", | ||
"image_index_name": "image", | ||
"video_index_name": "video", | ||
} | ||
cls.param = StoreConfig( | ||
label="test", | ||
type="es", | ||
parameters=StoreParameters( | ||
host_name=param_dict["host_name"], | ||
image_index_name=param_dict["image_index_name"], | ||
text_index_name=param_dict["text_index_name"], | ||
video_index_name=param_dict["video_index_name"], | ||
) | ||
) | ||
|
||
@classmethod | ||
def tearDownClass(cls) -> None: | ||
print("TEARING DOWN CLASS") | ||
|
||
@staticmethod | ||
def generate_document(post_id: str, representation: any): | ||
base_doc = { | ||
"e_kosh_id": "", | ||
"dataset": post_id, | ||
"metadata": None, | ||
"date_added": datetime.now().isoformat(), | ||
} | ||
|
||
def generator_doc(): | ||
for vector in representation: | ||
base_doc["_index"] = "video" | ||
base_doc["vid_vec"] = vector["vid_vec"] | ||
base_doc["is_avg"] = vector["is_avg"] | ||
base_doc["duration"] = vector["duration"] | ||
base_doc["n_keyframes"] = vector["n_keyframes"] | ||
yield base_doc | ||
|
||
return generator_doc | ||
|
||
# @skip | ||
def test_1_store_video_vector(self): | ||
es = ES(self.param) | ||
es.connect() | ||
|
||
# generate video embedding | ||
vid_vec_rep_resnet.initialize(param=None) | ||
file_name = "sample-cat-video.mp4" | ||
video = {"path": r"core/operators/sample_data/sample-cat-video.mp4"} | ||
embedding = vid_vec_rep_resnet.run(video) | ||
doc = self.generate_document(file_name, embedding) | ||
|
||
media_type = MediaType.VIDEO | ||
result = es.store(media_type, doc) | ||
print("result:", result) | ||
|
||
self.assertEqual(result["message"], "multiple media stored") | ||
|
||
# @skip | ||
def test_2_search_video_vector(self): | ||
es = ES(self.param) | ||
es.connect() | ||
es.optionally_create_index() | ||
|
||
# generate video embedding | ||
vid_vec_rep_resnet.initialize(param=None) | ||
file_name = "sample-cat-video.mp4" | ||
video = {"path": r"core/operators/sample_data/sample-cat-video.mp4"} | ||
embedding = vid_vec_rep_resnet.run(video) | ||
average_vector = next(embedding) | ||
|
||
search_result = es.find("video", average_vector.get('vid_vec')) | ||
print("SEARCH RESULTS \n : ") | ||
pp.pprint(search_result) | ||
self.assertEqual(search_result[0].get('dataset'), file_name) |
Oops, something went wrong.