Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model registry #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions inference_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@
from transformers import AutoModel, AutoTokenizer
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse

from mlflow.tracking import MlflowClient
from mlflow.entities import ViewType

client = QdrantClient("https://qdrant-mlsd-video-search.darkube.app", port=443)

app = FastAPI()

text_encoder = AutoModel.from_pretrained(os.environ['TEXT_ENCODER_MODEL'])
text_tokenizer = AutoTokenizer.from_pretrained(os.environ['TEXT_ENCODER_MODEL'])
MLFLOW_TRACKING_URI = "https://mlflow-mlsd-video-search.darkube.app/"
client = MlflowClient(tracking_uri=MLFLOW_TRACKING_URI)
experiments = client.search_experiments()
exp_id = list(filter(lambda e: e.name == 'clip-farsi', experiments))[0].experiment_id
runs = client.search_runs(
experiment_ids=exp_id,
filter_string="metrics.acc_at_10 >0.2",
run_view_type=ViewType.ACTIVE_ONLY,
max_results=5,
order_by=["metrics.acc_at_10 DESC"]
)
TEXT_ENCODER_MODEL = runs[0].data.tags['text_model']

text_encoder = AutoModel.from_pretrained(TEXT_ENCODER_MODEL)
text_tokenizer = AutoTokenizer.from_pretrained(TEXT_ENCODER_MODEL)


@app.get("/{video_name}/")
async def query(
video_name: str = Path(..., title="Video Name", description="Name of the video or 'ALL' to search in all videos"),
search_entry: str = Query(..., title="Search Entry", description="The search entry for text embedding"),
video_name: str = Path(..., title="Video Name",
description="Name of the video or 'ALL' to search in all videos"),
search_entry: str = Query(..., title="Search Entry", description="The search entry for text embedding"),
):
"""
Query for video frames based on the provided text search entry.
Expand Down Expand Up @@ -85,4 +100,3 @@ async def get_open_api_endpoint():
@app.get("/docs", include_in_schema=False)
async def get_documentation():
return JSONResponse(content=app.openapi())

1 change: 1 addition & 0 deletions inference_server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ torch --index-url https://download.pytorch.org/whl/cpu
torchvision --index-url https://download.pytorch.org/whl/cpu
transformers
qdrant_client
mlflow
17 changes: 16 additions & 1 deletion video_database/video_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import torchvision.transforms as transforms
from qdrant_client import QdrantClient
from qdrant_client.models import Record
from mlflow.tracking import MlflowClient
from mlflow.entities import ViewType


def image_to_string(image):
Expand All @@ -25,7 +27,20 @@ def image_to_string(image):
fps = int(video.get(cv2.CAP_PROP_FPS))
frame_interval = fps * 5 # capture a frame every 5 seconds

image_encoder = CLIPVisionModel.from_pretrained('arman-aminian/clip-farsi-vision').eval()
MLFLOW_TRACKING_URI = "https://mlflow-mlsd-video-search.darkube.app/"
client = MlflowClient(tracking_uri=MLFLOW_TRACKING_URI)
experiments = client.search_experiments()
exp_id = list(filter(lambda e: e.name == 'clip-farsi', experiments))[0].experiment_id
runs = client.search_runs(
experiment_ids=exp_id,
filter_string="metrics.acc_at_10 >0.2",
run_view_type=ViewType.ACTIVE_ONLY,
max_results=5,
order_by=["metrics.acc_at_10 DESC"]
)
VISION_ENCODER_MODEL = runs[0].data.tags['vision_model']

image_encoder = CLIPVisionModel.from_pretrained(VISION_ENCODER_MODEL).eval()

insert_data = []
currentframe = 0
Expand Down