-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (43 loc) · 1.79 KB
/
app.py
File metadata and controls
57 lines (43 loc) · 1.79 KB
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
import edgeiq
import time
def main():
instance_segmentation = edgeiq.InstanceSegmentation("alwaysai/mask_rcnn")
if edgeiq.is_opencv_cuda_available():
engine = edgeiq.Engine.DNN_CUDA
else:
engine = edgeiq.Engine.DNN
instance_segmentation.load(engine)
print("Engine: {}".format(instance_segmentation.engine))
print("Accelerator: {}\n".format(instance_segmentation.accelerator))
print("Model:\n{}\n".format(instance_segmentation.model_id))
print("Labels:\n{}\n".format(instance_segmentation.labels))
fps = edgeiq.FPS()
try:
with edgeiq.FileVideoStream('videos/sample.mkv') as video_stream, \
edgeiq.Streamer() as streamer:
time.sleep(2.0)
fps.start()
while True:
try:
frame = video_stream.read()
except edgeiq.NoMoreFrames:
video_stream.start()
frame = video_stream.read()
results = instance_segmentation.segment_image(frame)
# Generate text to display on streamer
text = ["Model: {}".format(instance_segmentation.model_id)]
text.append("Inference time: {:1.3f} s".
format(results.duration))
frame = instance_segmentation.markup_image(frame,
results.predictions)
streamer.send_data(frame, text)
fps.update()
if streamer.check_exit():
break
finally:
fps.stop()
print("elapsed time: {:.2f}".format(fps.get_elapsed_seconds()))
print("approx. FPS: {:.2f}".format(fps.compute_fps()))
print("Program Ending")
if __name__ == "__main__":
main()