From 95a295981488b627aa4710034e58917f6ac1d007 Mon Sep 17 00:00:00 2001 From: Aurora <5505558+duggalsu@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:11:40 +0530 Subject: [PATCH] Add cpu profiling and optimize operator - Added pyinstrument for cpu profiling - Added gitignore requirement for pyinstrument - Disabled compress function for operator - Removed ffmpy dependency as it is not required now --- src/api/.gitignore | 5 +++++ src/api/core/operators/vid_vec_rep_resnet.py | 21 +++++++++++-------- .../vid_vec_rep_resnet_requirements.in | 1 - .../vid_vec_rep_resnet_requirements.txt | 2 -- src/api/requirements.in | 1 + src/api/requirements.txt | 2 ++ 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/api/.gitignore b/src/api/.gitignore index 178e7cfc..a19adb13 100644 --- a/src/api/.gitignore +++ b/src/api/.gitignore @@ -1,3 +1,8 @@ credentials.json + +# memray *.bin *.html + +# pyinstrument +*.json diff --git a/src/api/core/operators/vid_vec_rep_resnet.py b/src/api/core/operators/vid_vec_rep_resnet.py index 96a24799..6f610345 100644 --- a/src/api/core/operators/vid_vec_rep_resnet.py +++ b/src/api/core/operators/vid_vec_rep_resnet.py @@ -3,8 +3,8 @@ def initialize(param): print("Installing packages for vid_vec_rep_resnet") - global TextBlob, os, np, cv2, qr, torch, data, models, transforms, Image, FFmpeg, wget - global imagenet_transform, ImageListDataset, VideoAnalyzer, gendata, compress_video + global TextBlob, os, np, cv2, qr, torch, data, models, transforms, Image, wget #, FFmpeg + global imagenet_transform, ImageListDataset, VideoAnalyzer, gendata #, compress_video import os import numpy as np @@ -15,7 +15,7 @@ def initialize(param): import torchvision.models as models import torchvision.transforms as transforms from PIL import Image - from ffmpy import FFmpeg + # from ffmpy import FFmpeg import wget imagenet_transform = transforms.Compose( @@ -26,6 +26,7 @@ def initialize(param): ] ) + ''' def compress_video(fname): newname = "/tmp/compressed.mp4" FNULL = open(os.devnull, "w") @@ -38,6 +39,8 @@ def compress_video(fname): ff.run(stdout=FNULL, stderr=FNULL) # os.remove(fname) return newname + ''' + def gendata(vid_analyzer): # average vector @@ -205,11 +208,11 @@ def run(file): fname = file["path"] fsize = os.path.getsize(fname) / 1e6 print("original size: ", fsize) - if fsize < 10: - print("compressing video") - fname = compress_video(fname) - fsize = os.path.getsize(fname) / 1e6 - print("compressed video size: ", fsize) + # if fsize < 10: + # print("compressing video") + # fname = compress_video(fname) + # fsize = os.path.getsize(fname) / 1e6 + # print("compressed video size: ", fsize) if fsize > 10: raise Exception("Video too large") @@ -219,7 +222,7 @@ def run(file): doable, error_msg = vid_analyzer.check_constraints() - os.remove(fname) + # os.remove(fname) if not doable: raise "Unsupported Video. Cannot index video." diff --git a/src/api/core/operators/vid_vec_rep_resnet_requirements.in b/src/api/core/operators/vid_vec_rep_resnet_requirements.in index 38e66f74..f125ba08 100644 --- a/src/api/core/operators/vid_vec_rep_resnet_requirements.in +++ b/src/api/core/operators/vid_vec_rep_resnet_requirements.in @@ -2,7 +2,6 @@ torch==2.1.2+cpu torchvision==0.16.2+cpu numpy==1.26.3 wget==3.2 -ffmpy==0.3.1 Pillow==10.2.0 scipy==1.11.4 opencv-python-headless==4.9.0.80 \ No newline at end of file diff --git a/src/api/core/operators/vid_vec_rep_resnet_requirements.txt b/src/api/core/operators/vid_vec_rep_resnet_requirements.txt index d57fc95c..0ed3fc57 100644 --- a/src/api/core/operators/vid_vec_rep_resnet_requirements.txt +++ b/src/api/core/operators/vid_vec_rep_resnet_requirements.txt @@ -10,8 +10,6 @@ certifi==2023.11.17 # via requests charset-normalizer==3.3.2 # via requests -ffmpy==0.3.1 - # via -r vid_vec_rep_resnet_requirements.in filelock==3.13.1 # via torch fsspec==2023.12.2 diff --git a/src/api/requirements.in b/src/api/requirements.in index 559e06d3..3d11be93 100644 --- a/src/api/requirements.in +++ b/src/api/requirements.in @@ -22,3 +22,4 @@ pytest==7.4.4 PyYAML==6.0.1 dacite==1.8.1 memray==1.11.0 # dev +pyinstrument==4.6.2 diff --git a/src/api/requirements.txt b/src/api/requirements.txt index 80c46902..08dace8d 100644 --- a/src/api/requirements.txt +++ b/src/api/requirements.txt @@ -171,6 +171,8 @@ pyasn1-modules==0.2.8 # via google-auth pygments==2.17.2 # via rich +pyinstrument==4.6.2 + # via -r requirements.in pytest==7.4.4 # via -r requirements.in python-dateutil==2.8.1