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

ensure fps limit of 120 enforced #299

Merged
merged 11 commits into from
Aug 13, 2024
2 changes: 1 addition & 1 deletion roboflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions roboflow/models/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ 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:
Expand Down
4 changes: 2 additions & 2 deletions roboflow/models/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 > 120:
raise Exception("FPS must be less than or equal to 120.")

if additional_models is None:
additional_models = []
Expand Down
56 changes: 56 additions & 0 deletions roboflow/roboflowpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ def get_workspace(args):
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,
args.fps,
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)
Expand Down Expand Up @@ -174,6 +192,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)
deployment.add_deployment_parser(subparsers)

return parser
Expand Down Expand Up @@ -332,6 +351,43 @@ 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.add_argument(
"-fps",
dest="fps",
type=int,
help="fps",
default=5,
)
run_video_inference_api_parser.set_defaults(func=run_video_inference_api)


def _add_infer_parser(subparsers):
infer_parser = subparsers.add_parser(
"infer",
Expand Down
2 changes: 2 additions & 0 deletions tests/manual/video_inference.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/env bash
python ../../roboflow/roboflowpy.py run_video_inference_api -a -p -v -f -fps