Skip to content

Commit b1d3eb6

Browse files
authored
[bash] Add tensor if sample application (#222)
Add tensor if sample applications. These samples show how to use passthrough mode and tensorpick mode. Signed-off-by: gichan-jang <gichan2.jang@samsung.com>
1 parent 66ffffc commit b1d3eb6

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## NNStreamer Native Sample Application - tensor_if
2+
### Introduction
3+
4+
This example passes camera video stream to a neural network using **tensor_filter**. The neural network detects faces of people in input stream.
5+
The tensor_if element controls the data stream depending on whether the face is detected from the filter.
6+
If the face is detected, start detecting objects.
7+
8+
### Graphical description of pipeline - tensor_if passthrough action
9+
10+
When the face is detected, the tensor_if operates in passthrough mode.
11+
12+
![pipeline-img](./tensorif_passthrough.png)
13+
14+
When the face is detected, the tensor_if operates in tensorpick mode.
15+
If there is a face, it detects the object, and if there is no face, it adjusts the colors of a video stream.
16+
17+
![pipeline-img](./tensor_if_tensorpick.png)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#video stream continuously
2+
gst-launch-1.0 \
3+
tensor_mux name=mux_0 ! tensor_demux name=demux_0 \
4+
v4l2src ! videoconvert ! video/x-raw,width=640,height=480,format=RGB,framerate=5/1 ! videocrop right=160 ! tee name=t_raw \
5+
t_raw. ! queue leaky=2 max-size-buffers=2 ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! mux_0.sink_0 \
6+
t_raw. ! queue leaky=2 max-size-buffers=2 ! videoconvert ! videoscale ! video/x-raw,height=300,width=300,format=BGR ! tensor_converter ! \
7+
tensor_transform mode=typecast option=float32 ! tensor_transform mode=dimchg option=0:2 ! \
8+
tensor_filter framework=openvino model=openvino_models/face-detection-retail-0005.xml accelerator=true:cpu ! \
9+
tensor_if name=tif compared_value=A_VALUE compared-value-option=2:0:0:0,0 \
10+
supplied-value=0.7 operator=GE then=PASSTHROUGH else=SKIP \
11+
tif.src_0 ! queue leaky=2 max-size-buffers=2 ! mux_0.sink_1 demux_0.src_0 ! tee name=t_demux \
12+
t_demux. ! queue leaky=2 max-size-buffers=2 ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! \
13+
tensor_filter framework=tensorflow-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! \
14+
tensor_decoder mode=bounding_boxes option1=tflite-ssd option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=480:480 option5=300:300 ! \
15+
compositor name=mix sink_0::zorder=2 sink_1::zorder=1 ! videoconvert ! \
16+
textoverlay text="Stop detecting objects if face is not detected" valignment=top halignment=left font-desc="Sans, 32" ! ximagesink \
17+
t_raw. ! queue leaky=2 max-size-buffers=2 ! mix.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
gst-launch-1.0 v4l2src ! videoconvert ! video/x-raw,width=640,height=480,format=RGB,framerate=5/1 ! videocrop left=80 right=80 ! tee name=t_raw \
3+
t_raw. ! queue ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! mux_0.sink_0 \
4+
t_raw. ! queue ! videoconvert ! video/x-raw,format=RGBx ! burn adjustment=30 ! videoconvert ! tensor_converter ! mux_0.sink_1 \
5+
t_raw. ! queue ! videoconvert ! videoscale ! video/x-raw,height=300,width=300,format=BGR ! tensor_converter ! \
6+
tensor_transform mode=typecast option=float32 ! tensor_transform mode=dimchg option=0:2 ! \
7+
tensor_filter framework=openvino model=openvino_models/face-detection-retail-0005.xml accelerator=true:cpu ! mux_0.sink_2 \
8+
tensor_mux name=mux_0 ! tensor_if name=tif compared_value=A_VALUE compared-value-option=2:0:0:0,2 \
9+
supplied-value=0.7 operator=GE then=TENSORPICK then-option=0 else=TENSORPICK else-option=1 \
10+
tif.src_0 ! queue leaky=2 max-size-buffers=2 ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! \
11+
tensor_filter framework=tensorflow-lite model=tflite_model/ssd_mobilenet_v2_coco.tflite ! \
12+
tensor_decoder mode=bounding_boxes option1=tflite-ssd option2=tflite_model/coco_labels_list.txt option3=tflite_model/box_priors.txt option4=480:480 option5=300:300 ! \
13+
compositor name=mix sink_0::zorder=2 sink_1::zorder=1 ! videoconvert ! \
14+
textoverlay text="Stop detecting objects if face is not detected" valignment=top halignment=left font-desc="Sans, 32" ! ximagesink sync=false async=false \
15+
tif.src_1 ! queue leaky=2 max-size-buffers=2 ! tensor_decoder mode=direct_video ! videoconvert ! \
16+
textoverlay text="Enabled when face is not detected" valignment=top halignment=left font-desc="Sans, 32" ! ximagesink sync=false async=false \
17+
t_raw. ! queue leaky=2 max-size-buffers=2 ! mix.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
install_data(['gst-launch-tensorif-passthrough.sh',
2+
'gst-launch-tensorif-tensorpick.sh'],
3+
install_dir: examples_install_dir
4+
)
79.9 KB
Loading
60.1 KB
Loading

bash_script/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ endif
55
if have_tensorflow_lite
66
subdir('example_object_detection_tensorflow_lite')
77
subdir('example_image_segmentation_tensorflow_lite')
8+
if have_openvino
9+
subdir('example_tensorif')
10+
endif
811
endif
912

1013
if have_openvino

0 commit comments

Comments
 (0)