From 3c13740f8d96fe5d423f29c4c0fa1ae87e7ab982 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 16:10:31 +0000 Subject: [PATCH 01/10] increase fps limit to 60 for video inference api --- roboflow/models/video.py | 4 +-- roboflow/roboflowpy.py | 47 ++++++++++++++++++++++++++++++++- tests/manual/video_inference.sh | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 tests/manual/video_inference.sh diff --git a/roboflow/models/video.py b/roboflow/models/video.py index 03fdec19..72df7f87 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -97,8 +97,8 @@ def predict( # type: ignore[override] url = urljoin(API_URL, f"/video_upload_signed_url/?api_key={self.__api_key}") - if fps > 30: - raise Exception("FPS must be less than or equal to 30.") + if fps > 60: + raise Exception("FPS must be less than or equal to 60.") if additional_models is None: additional_models = [] diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index cf3280b9..98cef2b1 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -13,7 +13,6 @@ from roboflow.models.object_detection import ObjectDetectionModel from roboflow.models.semantic_segmentation import SemanticSegmentationModel - def login(args): roboflow.login() @@ -111,7 +110,24 @@ def get_workspace(args): api_key = load_roboflow_api_key(args.workspaceId) workspace_json = rfapi.get_workspace(api_key, args.workspaceId) print(json.dumps(workspace_json, indent=2)) + + +def run_video_inference_api(args): + rf = roboflow.Roboflow(args.api_key) + project = rf.workspace().project(args.project) + version = project.version(args.version_number) + model = project.version(version).model + #model = VideoInferenceModel(args.api_key, project.id, version.version, project.id) # Pass dataset_id + # Pass model_id and version + job_id, signed_url, expire_time = model.predict_video( + args.video_file, + fps=40, + prediction_type="batch-video", + ) + results = model.poll_until_video_results(job_id) + with open("test_video.json", "w") as f: + json.dump(results, f) def get_workspace_project_version(args): # api_key = load_roboflow_api_key(args.workspaceId) @@ -173,6 +189,7 @@ def _argparser(): _add_workspaces_parser(subparsers) _add_upload_model_parser(subparsers) _add_get_workspace_project_version_parser(subparsers) + _add_run_video_inference_api_parser(subparsers) return parser @@ -329,6 +346,34 @@ def _add_workspaces_parser(subparsers): ) workspaceget_parser.set_defaults(func=get_workspace) +def _add_run_video_inference_api_parser(subparsers): + run_video_inference_api_parser = subparsers.add_parser( + "run_video_inference_api", + help="run video inference api", + ) + + run_video_inference_api_parser.add_argument( + "-a", + dest="api_key", + help="api_key", + ) + run_video_inference_api_parser.add_argument( + "-p", + dest="project", + help="project_id to upload the image into", + ) + run_video_inference_api_parser.add_argument( + "-v", + dest="version_number", + type=int, + help="version number to upload the model to", + ) + run_video_inference_api_parser.add_argument( + "-f", + dest="video_file", + help="path to video file", + ) + run_video_inference_api_parser.set_defaults(func=run_video_inference_api) def _add_infer_parser(subparsers): infer_parser = subparsers.add_parser( diff --git a/tests/manual/video_inference.sh b/tests/manual/video_inference.sh new file mode 100755 index 00000000..5901a7eb --- /dev/null +++ b/tests/manual/video_inference.sh @@ -0,0 +1 @@ +python ../../roboflow/roboflowpy.py run_video_inference_api -a -p -v -f From 401a8b3730e776cb79711980d668f49bec3838f3 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 16:41:46 +0000 Subject: [PATCH 02/10] increase video inference fps to 120 --- roboflow/models/inference.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/roboflow/models/inference.py b/roboflow/models/inference.py index bbbc5be6..c541f329 100644 --- a/roboflow/models/inference.py +++ b/roboflow/models/inference.py @@ -167,10 +167,9 @@ def predict_video( signed_url_expires = None url = urljoin(API_URL, "/video_upload_signed_url?api_key=" + self.__api_key) - - # if fps > 5: - # raise Exception("FPS must be less than or equal to 5.") - + if fps > 120: + raise Exception("FPS must be less than or equal to 120.") + for model in additional_models: if model not in SUPPORTED_ADDITIONAL_MODELS: raise Exception(f"Model {model} is not supported for video inference.") From c98abbd97f84333bbcb18966b5346ab2140586a0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:44:30 +0000 Subject: [PATCH 03/10] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto?= =?UTF-8?q?=20format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roboflow/models/inference.py | 2 +- roboflow/roboflowpy.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/roboflow/models/inference.py b/roboflow/models/inference.py index c541f329..9ec24f50 100644 --- a/roboflow/models/inference.py +++ b/roboflow/models/inference.py @@ -169,7 +169,7 @@ def predict_video( url = urljoin(API_URL, "/video_upload_signed_url?api_key=" + self.__api_key) if fps > 120: raise Exception("FPS must be less than or equal to 120.") - + for model in additional_models: if model not in SUPPORTED_ADDITIONAL_MODELS: raise Exception(f"Model {model} is not supported for video inference.") diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index 98cef2b1..02266f8c 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -13,6 +13,7 @@ from roboflow.models.object_detection import ObjectDetectionModel from roboflow.models.semantic_segmentation import SemanticSegmentationModel + def login(args): roboflow.login() @@ -110,7 +111,7 @@ def get_workspace(args): api_key = load_roboflow_api_key(args.workspaceId) workspace_json = rfapi.get_workspace(api_key, args.workspaceId) print(json.dumps(workspace_json, indent=2)) - + def run_video_inference_api(args): rf = roboflow.Roboflow(args.api_key) @@ -118,17 +119,18 @@ def run_video_inference_api(args): version = project.version(args.version_number) model = project.version(version).model - #model = VideoInferenceModel(args.api_key, project.id, version.version, project.id) # Pass dataset_id - # Pass model_id and version + # model = VideoInferenceModel(args.api_key, project.id, version.version, project.id) # Pass dataset_id + # Pass model_id and version job_id, signed_url, expire_time = model.predict_video( - args.video_file, - fps=40, - prediction_type="batch-video", + args.video_file, + fps=40, + prediction_type="batch-video", ) results = model.poll_until_video_results(job_id) with open("test_video.json", "w") as f: json.dump(results, f) + def get_workspace_project_version(args): # api_key = load_roboflow_api_key(args.workspaceId) rf = roboflow.Roboflow(args.api_key) @@ -346,12 +348,13 @@ def _add_workspaces_parser(subparsers): ) workspaceget_parser.set_defaults(func=get_workspace) + def _add_run_video_inference_api_parser(subparsers): run_video_inference_api_parser = subparsers.add_parser( "run_video_inference_api", help="run video inference api", ) - + run_video_inference_api_parser.add_argument( "-a", dest="api_key", @@ -375,6 +378,7 @@ def _add_run_video_inference_api_parser(subparsers): ) run_video_inference_api_parser.set_defaults(func=run_video_inference_api) + def _add_infer_parser(subparsers): infer_parser = subparsers.add_parser( "infer", From a51842e8f90d64cd5251412d58d26600f28db128 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 16:45:01 +0000 Subject: [PATCH 04/10] increase fps to 120 in video.py --- roboflow/models/video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roboflow/models/video.py b/roboflow/models/video.py index 72df7f87..4677d639 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -97,7 +97,7 @@ def predict( # type: ignore[override] url = urljoin(API_URL, f"/video_upload_signed_url/?api_key={self.__api_key}") - if fps > 60: + if fps > 120: raise Exception("FPS must be less than or equal to 60.") if additional_models is None: From 7ff81d8359b94be2b668a51f59081450d5aee9b7 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 16:52:03 +0000 Subject: [PATCH 05/10] increase fps to 120 in video.py --- roboflow/models/video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roboflow/models/video.py b/roboflow/models/video.py index 4677d639..401a2aab 100644 --- a/roboflow/models/video.py +++ b/roboflow/models/video.py @@ -98,7 +98,7 @@ def predict( # type: ignore[override] url = urljoin(API_URL, f"/video_upload_signed_url/?api_key={self.__api_key}") if fps > 120: - raise Exception("FPS must be less than or equal to 60.") + raise Exception("FPS must be less than or equal to 120.") if additional_models is None: additional_models = [] From 8ccef426eab1a11e63f50c1d2924e76b0d920a85 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 16:57:20 +0000 Subject: [PATCH 06/10] new release 1.1.38 --- roboflow/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roboflow/__init__.py b/roboflow/__init__.py index f7565489..a8c77726 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -15,7 +15,7 @@ from roboflow.models import CLIPModel, GazeModel # noqa: F401 from roboflow.util.general import write_line -__version__ = "1.1.37" +__version__ = "1.1.38" def check_key(api_key, model, notebook, num_retries=0): From d03f25697dc96a270c3bf332f4d82baac5952a05 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 18:31:39 +0000 Subject: [PATCH 07/10] add fps argument --- roboflow/roboflowpy.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index 02266f8c..324bb7be 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -123,7 +123,7 @@ def run_video_inference_api(args): # Pass model_id and version job_id, signed_url, expire_time = model.predict_video( args.video_file, - fps=40, + args.fps, prediction_type="batch-video", ) results = model.poll_until_video_results(job_id) @@ -376,6 +376,12 @@ def _add_run_video_inference_api_parser(subparsers): dest="video_file", help="path to video file", ) + run_video_inference_api_parser.add_argument( + "-fps", + dest="fps", + type=int, + help="fps", + ) run_video_inference_api_parser.set_defaults(func=run_video_inference_api) From aaea73012d0637b0b8082ec598fae9cbed7f976b Mon Sep 17 00:00:00 2001 From: ryanjball Date: Mon, 29 Jul 2024 19:44:04 +0000 Subject: [PATCH 08/10] default fps to 5 in manual video inference api test --- roboflow/roboflowpy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index 324bb7be..a0a3c41f 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -381,6 +381,7 @@ def _add_run_video_inference_api_parser(subparsers): dest="fps", type=int, help="fps", + default=5, ) run_video_inference_api_parser.set_defaults(func=run_video_inference_api) From 30c9463547205eff3106e7960f3fda6d92782fc9 Mon Sep 17 00:00:00 2001 From: ryanjball Date: Tue, 13 Aug 2024 19:40:16 +0000 Subject: [PATCH 09/10] add Shebang line to video_inference.sh and bump python version --- roboflow/__init__.py | 2 +- tests/manual/video_inference.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/roboflow/__init__.py b/roboflow/__init__.py index a8c77726..c75d15f9 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -15,7 +15,7 @@ from roboflow.models import CLIPModel, GazeModel # noqa: F401 from roboflow.util.general import write_line -__version__ = "1.1.38" +__version__ = "1.1.39" def check_key(api_key, model, notebook, num_retries=0): diff --git a/tests/manual/video_inference.sh b/tests/manual/video_inference.sh index 5901a7eb..e43854bd 100755 --- a/tests/manual/video_inference.sh +++ b/tests/manual/video_inference.sh @@ -1 +1,2 @@ -python ../../roboflow/roboflowpy.py run_video_inference_api -a -p -v -f +#!/bin/env bash +python ../../roboflow/roboflowpy.py run_video_inference_api -a -p -v -f -fps From 67269e132b1fd6d25a80844b5c50904a479133a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 19:49:41 +0000 Subject: [PATCH 10/10] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto?= =?UTF-8?q?=20format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roboflow/__init__.py | 1 - roboflow/roboflowpy.py | 1 - 2 files changed, 2 deletions(-) diff --git a/roboflow/__init__.py b/roboflow/__init__.py index 312eac8b..c75d15f9 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -15,7 +15,6 @@ from roboflow.models import CLIPModel, GazeModel # noqa: F401 from roboflow.util.general import write_line - __version__ = "1.1.39" diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index 622b86e5..49228095 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -195,7 +195,6 @@ def _argparser(): _add_run_video_inference_api_parser(subparsers) deployment.add_deployment_parser(subparsers) - return parser