-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputer_vision.py
67 lines (54 loc) · 1.67 KB
/
computer_vision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import argparse
import signal
import sys
import os
import logging
from functools import partial
from typing import Union, Optional
from inference.core.interfaces.stream.inference_pipeline import InferencePipeline
from inference.core.interfaces.stream.sinks import render_boxes
PIPELINE: Optional[InferencePipeline] = None
ROBOFLOW_API_KEY: str = os.getenv("ROBOFLOW_API_KEY")
FPS: int = 30
def infer(
model_id: str,
source: Union[str, int],
on_prediction: Optional[callable] = partial(render_boxes, display_statistics=True),
):
logger = logging.getLogger(__name__)
logger.error("LOG JM: infer function called")
global PIPELINE
PIPELINE = InferencePipeline.init(
model_id=model_id,
video_reference=source,
on_prediction=on_prediction,
api_key=ROBOFLOW_API_KEY,
max_fps=FPS,
)
PIPELINE.start()
# Stuff to handle things if you execute via terminal
def signal_handler(sig, frame):
print("Terminating")
if PIPELINE is not None:
PIPELINE.terminate()
PIPELINE.join()
sys.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser("Simple InferencePipeline demo")
parser.add_argument(
"--model_id",
help=f"ID of the model",
required=False,
type=str,
default="rock-paper-scissors-sxsw/11",
)
parser.add_argument(
"--source",
help=f"Reference to video source - can be file, stream or id of device",
required=False,
default=0,
)
signal.signal(signal.SIGINT, signal_handler)
print("Press Ctrl+C to terminate")
args = parser.parse_args()
infer(model_id=args.model_id, source=args.source)