-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_seg.py
83 lines (68 loc) · 2.26 KB
/
check_seg.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import argparse
from segnet_utils import *
from jetson_inference import segNet
from jetson_utils import (
videoSource, videoOutput, cudaOverlay, cudaDeviceSynchronize
)
def main():
camera = videoSource('/dev/video0')
display = videoOutput('display://0')
args = argparse.Namespace(
filter_mode='linear',
visualize='overlay,mask',
ignore_class='void',
alpha='150.0',
stats=False
)
net = segNet(
model="data/models/segmentation/fcn_resnet34.onnx",
labels="data/models/segmentation/labels.txt",
input_blob="input_0", output_blob="output_0"
)
net.SetOverlayAlpha(150)
buffers = SegmentationBuffers(net, args)
# process frames until EOS or the user exits
while True:
# capture the next image
image = camera.Capture()
if image is None: # timeout
continue
# allocate buffers for this size image
buffers.Alloc(image.shape, image.format)
# process the segmentation network
net.Process(image, ignore_class=args.ignore_class)
# generate the overlay
if buffers.overlay:
net.Overlay(buffers.overlay, filter_mode=args.filter_mode)
# generate the mask
if buffers.mask:
net.Mask(buffers.mask, filter_mode=args.filter_mode)
# composite the images
if buffers.composite:
cudaOverlay(
buffers.overlay,
buffers.composite,
0, 0
)
cudaOverlay(
buffers.mask,
buffers.composite,
buffers.overlay.width, 0
)
# render the output image
display.Render(buffers.output)
# update the title bar
display.SetStatus(
f'Running Segmentation model at {net.GetNetworkFPS():.0f} FPS'
)
# print out performance info
cudaDeviceSynchronize()
net.PrintProfilerTimes()
# compute segmentation class stats
if args.stats:
buffers.ComputeStats()
# exit on input/output EOS
if not camera.IsStreaming() or not display.IsStreaming():
break
if __name__ == "__main__":
main()