# Run a TensorFlow Lite model using the Gstreamer-based Qualcomm® Intelligent Multimedia
        SDK (IM SDK)

Source: [https://docs.qualcomm.com/doc/80-70014-54/topic/run-a-tensorflow-lite-model-using-the-gstreamer-based-qim-sdk.html](https://docs.qualcomm.com/doc/80-70014-54/topic/run-a-tensorflow-lite-model-using-the-gstreamer-based-qim-sdk.html)

The RB3 Gen 2 Vision kit ships with precompiled end-to-end TensorFlow Lite sample
        applications to run sample TensorFlow Lite models.

The gst-ai-classification sample application uses IM SDK plug-ins to run a TensorFlow
            Lite classification model on the RB3 Gen 2 device with hardware acceleration using
            TensorFlow Lite delegates.

Figure : Workflow to run a TensorFlow Lite model using IM SDK
            
            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by Microsoft Visio, SVG Export workflow-to-run-tflite-model-using-qualcomm-im-sdk.svg Page-1 -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="12.8802in" height="4.20833in" viewbox="0 0 927.375 303" xml:space="preserve" color-interpolation-filters="sRGB" class="st13"><v:documentproperties v:langid="1033" v:viewmarkup="false">	<v:userdefs>		<v:ud v:nameu="msvNoAutoConnect" v:val="VT0(1):26"></v:ud>	</v:userdefs></v:documentproperties>
<style>.svg-1 .st1 { fill: #f7f8fa; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.75 }
.svg-1 .st2 { fill: none; marker-end: url("#mrkr5-8"); marker-start: url("#mrkr5-6"); stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st3 { fill: #3253dc; fill-opacity: 1; stroke: #3253dc; stroke-opacity: 1; stroke-width: 0.28409090909091 }
.svg-1 .st4 { fill: none; stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st5 { fill: #000000; font-family: Arial; font-size: 0.75em }
.svg-1 .st6 { font-size: 1em }
.svg-1 .st7 { fill: #3253dc; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 6.375 }
.svg-1 .st8 { fill: #3253dc; fill-opacity: 1; stroke: #3253dc; stroke-opacity: 1; stroke-width: 0.71669477234401 }
.svg-1 .st9 { marker-end: url("#mrkr5-8"); stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st10 { fill: none; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st11 { marker-end: url("#mrkr5-8"); marker-start: url("#mrkr5-105"); stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st12 { stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st13 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<defs id="Markers">	<g id="lend5">		<path d="M 2 1 L 0 0 L 1.98117 -0.993387 C 1.67173 -0.364515 1.67301 0.372641 1.98465 1.00043 " style="stroke:none"></path>	</g>	<marker id="mrkr5-6" class="st3" v:arrowtype="5" v:arrowsize="2" v:setback="6.16" refx="6.16" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(3.52) "></use>	</marker>	<marker id="mrkr5-8" class="st3" v:arrowtype="5" v:arrowsize="2" v:setback="6.16" refx="-6.16" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(-3.52,-3.52) "></use>	</marker>	<marker id="mrkr5-48" class="st8" v:arrowtype="5" v:arrowsize="2" v:setback="2.44176" refx="-2.4417647058824" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(-1.3952941176471,-1.3952941176471) "></use>	</marker>	<marker id="mrkr5-105" class="st3" v:arrowtype="5" v:arrowsize="2" v:setback="5.8" refx="5.8" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(3.52) "></use>	</marker></defs><g v:mid="0" v:index="1" v:groupcontext="foregroundPage">	<title>Page-1</title>	<v:pageproperties v:drawingscale="1" v:pagescale="1" v:drawingunits="19" v:shadowoffsetx="9" v:shadowoffsety="-9"></v:pageproperties>	<v:layer v:name="Connector" v:index="0"></v:layer>	<g id="shape1002-1" v:mid="1002" v:groupcontext="shape" transform="translate(18.2813,-18)">		<title></title>		<rect x="0" y="36" width="891.094" height="267" class="st1"></rect>	</g>	<g id="shape1000-3" v:mid="1000" v:groupcontext="shape" transform="translate(306.562,-26.0619)">		<title></title>		<rect x="0" y="82.5" width="139.5" height="220.5" class="st2"></rect>	</g>	<g id="shape1-9" v:mid="1" v:groupcontext="shape" transform="translate(323.812,-179.437)">		<title></title>		<desc>TensorFlow Lite inferencing</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="49.5" cy="280.5" width="99" height="45"></v:textrect>		<rect x="0" y="258" width="99" height="45" class="st4"></rect>		<text x="17.49" y="277.8" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>TensorFlow Lite <tspan x="27.49" dy="1.2em" class="st6">inferencing</tspan></text>		</g>	<g id="shape3-13" v:mid="3" v:groupcontext="shape" transform="translate(323.812,-107.437)">		<title></title>		<desc>Delegate (CPU, GPU, external)</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="49.5" cy="280.5" width="99" height="45"></v:textrect>		<rect x="0" y="258" width="99" height="45" class="st4"></rect>		<text x="31.49" y="277.8" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Delegate<v:lf></v:lf><tspan x="6.24" dy="1.2em" class="st6">(CPU, GPU, external)</tspan></text>		</g>	<g id="shape4-17" v:mid="4" v:groupcontext="shape" transform="translate(323.812,-35.4369)">		<title></title>		<desc>External: Qualcomm Hexagon Tensor Processor</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="49.5" cy="280.5" width="99" height="45"></v:textrect>		<rect x="0" y="258" width="99" height="45" class="st4"></rect>		<text x="31.74" y="272.4" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>External: <v:lf></v:lf><tspan x="8.48" dy="1.2em" class="st6">Qualcomm Hexagon </tspan><tspan x="13.99" dy="1.2em" class="st6">Tensor Processor</tspan></text>		</g>	<g id="shape5-22" v:mid="5" v:groupcontext="shape" transform="translate(205.687,-179.437)">		<title></title>		<desc>Preprocessing</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="40.5" cy="280.5" width="81" height="45"></v:textrect>		<rect x="0" y="258" width="81" height="45" class="st4"></rect>		<text x="11.74" y="283.2" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Preprocessing</text>		</g>	<g id="shape6-25" v:mid="6" v:groupcontext="shape" transform="translate(205.687,-35.4369)">		<title></title>		<desc>TensorFlow Lite model</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="40.5" cy="280.5" width="81" height="45"></v:textrect>		<rect x="0" y="258" width="81" height="45" class="st4"></rect>		<text x="8.49" y="277.8" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>TensorFlow Lite <tspan x="28.24" dy="1.2em" class="st6">model</tspan></text>		</g>	<g id="shape7-29" v:mid="7" v:groupcontext="shape" transform="translate(97.6875,-179.437)">		<title></title>		<desc>Camera source</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="40.5" cy="280.5" width="81" height="45"></v:textrect>		<rect x="0" y="258" width="81" height="45" class="st4"></rect>		<text x="9.74" y="283.2" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Camera source</text>		</g>	<g id="shape8-32" v:mid="8" v:groupcontext="shape" transform="translate(458.812,-179.437)">		<title></title>		<desc>Postproccesing</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="40.5" cy="280.5" width="81" height="45"></v:textrect>		<rect x="0" y="258" width="81" height="45" class="st4"></rect>		<text x="9.73" y="283.2" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Postproccesing</text>		</g>	<g id="shape9-35" v:mid="9" v:groupcontext="shape" transform="translate(618.562,-152.437)">		<title></title>		<desc>qtivcomposer (Layer composition)</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="45.5625" cy="258" width="91.13" height="90"></v:textrect>		<rect x="0" y="213" width="91.125" height="90" class="st4"></rect>		<text x="18.8" y="255.3" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtivcomposer<v:lf></v:lf><tspan x="6.05" dy="1.2em" class="st6">(Layer composition)</tspan></text>		</g>	<g id="group19-39" transform="translate(61.6875,-184.462) scale(-1,1)" v:mid="19" v:groupcontext="group">		<title></title>		<g id="shape20-40" v:mid="20" v:groupcontext="shape">			<title></title>			<path d="M37.83 282.18 L26.73 290.92 L17.99 287.32 L17.99 288.1 C17.99 292.05 14.75 295.29 10.79 295.29 L3.08 295.29						 L3.08 303 L0 303 L0 268.05 L3.08 268.05 L3.08 292.21 L10.79 292.21 C13.05 292.21 14.9 290.36 14.9 288.1						 L14.9 286.09 L5.6 282.18 L10.33 270.77 L37.83 282.18 ZM16.45 283.47 C17.58 283.47 18.5 282.54 18.5 281.41						 C18.5 280.28 17.58 279.36 16.45 279.36 C15.32 279.36 14.39 280.28 14.39 281.41 C14.39 282.54 15.32 283.47						 16.45 283.47 Z" class="st7"></path>		</g>		<g id="shape21-42" v:mid="21" v:groupcontext="shape" transform="translate(32.1739,-12.1808)">			<title></title>			<path d="M4.57 297.86 L8.33 299.4 L3.75 303 L0 301.46 L4.57 297.86 Z" class="st7"></path>		</g>	</g>	<g id="group22-44" transform="translate(862.875,-181.463)" v:mid="22" v:groupcontext="group">		<title></title>		<g id="shape23-45" v:mid="23" v:groupcontext="shape" transform="translate(0,-2.77538)">			<title></title>			<path d="M38.48 268.05 C39.59 268.05 40.5 268.98 40.5 270.11 L40.5 294.78 C40.5 295.91 39.59 296.83 38.48 296.83						 L24.3 296.83 L24.3 299.92 L29.36 299.92 L29.36 303 L11.14 303 L11.14 299.92 L16.2 299.92 L16.2 296.83						 L2.03 296.83 C0.91 296.83 0 295.91 0 294.78 L0 270.11 C0 268.98 0.91 268.05 2.03 268.05 L38.48 268.05						 ZM37.46 293.75 L37.46 271.13 L3.04 271.13 L3.04 293.75 L37.46 293.75 Z" class="st7"></path>		</g>	</g>	<g id="shape26-49" v:mid="26" v:groupcontext="shape" transform="translate(61.6875,-201.937)">		<title></title>		<path d="M0 303 L29.84 303" class="st9"></path>	</g>	<g id="shape27-54" v:mid="27" v:groupcontext="shape" v:layermember="0" transform="translate(178.688,-192.188)">		<title></title>		<path d="M0 294 L20.84 294" class="st9"></path>	</g>	<g id="shape29-59" v:mid="29" v:groupcontext="shape" v:layermember="0" transform="translate(422.812,-192.937)">		<title></title>		<path d="M0 294 L29.84 294" class="st9"></path>	</g>	<g id="shape30-64" v:mid="30" v:groupcontext="shape" v:layermember="0" transform="translate(539.812,-192.937)">		<title></title>		<path d="M0 294 L72.59 294" class="st9"></path>	</g>	<g id="shape31-69" v:mid="31" v:groupcontext="shape" transform="translate(543.187,-201.937)">		<title></title>		<desc>Classification</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="9.49" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Classification</text>		</g>	<g id="shape33-72" v:mid="33" v:groupcontext="shape" transform="translate(536.437,-185.25)">		<title></title>		<desc>Metadata</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="17.24" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Metadata</text>		</g>	<g id="shape34-75" v:mid="34" v:groupcontext="shape" transform="translate(736.687,-152.437)">		<title></title>		<desc>Waylandsink (Display rendering)</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="45.5625" cy="258" width="91.13" height="90"></v:textrect>		<rect x="0" y="213" width="91.125" height="90" class="st4"></rect>		<text x="20.05" y="255.3" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Waylandsink<v:lf></v:lf><tspan x="7.55" dy="1.2em" class="st6">(Display rendering)</tspan></text>		</g>	<g id="shape36-79" v:mid="36" v:groupcontext="shape" transform="translate(286.687,-201.937)">		<title></title>		<path d="M0 303 L30.96 303" class="st9"></path>	</g>	<g id="shape37-84" v:mid="37" v:groupcontext="shape" transform="translate(286.687,-57.9369)">		<title></title>		<path d="M0 303 L30.96 303" class="st9"></path>	</g>	<g id="shape39-89" v:mid="39" v:groupcontext="shape" transform="translate(709.687,-201.937)">		<title></title>		<path d="M0 303 L18 303 L20.84 303" class="st9"></path>	</g>	<g id="shape40-94" v:mid="40" v:groupcontext="shape" transform="translate(827.812,-201.937)">		<title></title>		<path d="M0 303 L29.5 303" class="st9"></path>	</g>	<g id="shape41-99" v:mid="41" v:groupcontext="shape" transform="translate(675.187,195.563) rotate(90)">		<title></title>		<path d="M5.8 303 L6.16 303 L20.84 303" class="st11"></path>	</g>	<g id="shape42-107" v:mid="42" v:groupcontext="shape" transform="translate(675.187,123.563) rotate(90)">		<title></title>		<path d="M5.8 303 L6.16 303 L20.84 303" class="st11"></path>	</g>	<g id="shape43-114" v:mid="43" v:groupcontext="shape" transform="translate(102.187,-225.75)">		<title></title>		<desc>qtiqmmfsrc</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="14" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtiqmmfsrc</text>		</g>	<g id="shape44-117" v:mid="44" v:groupcontext="shape" transform="translate(210.187,-225.75)">		<title></title>		<desc>qtimlvconverter</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="5.49" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimlvconverter</text>		</g>	<g id="shape45-120" v:mid="45" v:groupcontext="shape" transform="translate(337.312,-225.75)">		<title></title>		<desc>qtimltflite</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="18.25" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimltflite</text>		</g>	<g id="shape46-123" v:mid="46" v:groupcontext="shape" transform="translate(452.625,-225.75)">		<title></title>		<desc>qtiqmlvclassification</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="45.5625" cy="296.25" width="91.13" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="91.125" height="13.5" class="st10"></rect>		<text x="5.8" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtiqmlvclassification</text>		</g>	<g id="shape47-126" v:mid="47" v:groupcontext="shape" v:layermember="0" transform="translate(190.385,-201.937)">		<title></title>		<path d="M0 303 L0 240 L483.3 240" class="st12"></path>	</g>	<g id="shape48-129" v:mid="48" v:groupcontext="shape" v:layermember="0" transform="translate(664.687,-264.937)">		<title></title>		<path d="M9 303 L9 319.34" class="st9"></path>	</g>	<g id="shape50-134" v:mid="50" v:groupcontext="shape" transform="translate(405,-266.25)">		<title></title>		<desc>Live stream</desc>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="36" cy="296.25" width="72" height="13.5"></v:textrect>		<rect x="0" y="289.5" width="72" height="13.5" class="st10"></rect>		<text x="12.74" y="298.95" class="st5" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Live stream</text>		</g></g>
</svg>

The gst-ai-classification sample application does the following:

1. Opens the IMX577 camera present on the RB3 Gen 2 Vision kit with a specific
                resolution and fps, for example, 1080p at 30 fps.
2. Preprocesses each camera frame to input to a classification model.
    For example,
                    the gst-ai-classification sample application does the following:

    1. Downscales a 1080p frame to a 224 x 224 resolution.
    2. Normalizes the input frame based on the model requirements.
3. The qtimltflite IM SDK plug-in, which is written on top of the TensorFlow Lite C++
                API, does the following:
    1. Loads the sample TensorFlow Lite classification model.
    2. Performs inference on the model provided with hardware acceleration.
4. Postprocesses the output from the inference, that is, extract the label with highest
                predicted probability within the output tensor.
5. Overlays the inference result on the original camera input image and displays it on
                the connected monitor.

## Download sample models

To download sample models and copy them to the RB3 Gen 2 Vision kit, do the
                following:

1. To download sample models and the corresponding label files, run the following
                    command:

        wget https://github.com/quic/sample-apps-for-qualcomm-linux/releases/download/v0.1.0/v0.1.0.tar.gzCopy to clipboard
2. To extract files, run the following
                    command:

        tar -zxvf v0.1.0.tar.gzCopy to clipboard
3. To copy the models and label files to the device using the Secure Copy Protocol
                    (SCP), run the following
                        commands:

        # For SCP, run the following command:
        ssh root@[ip-addr]
        setenforce 0
        mount -o remount,rw /
        exitCopy to clipboard

        # Copy files securely
        scp v0.1.0/* root@[ip-addr]:/opt/Copy to clipboard

Note: When prompted for a password, enter
                    <var class="keyword varname">oelinux123</var>.

## Execute TensorFlow Lite model with sample application

1. To run inference using TensorFlow Lite Runtime, run the following
                        commands:

        ssh root@[ip-addr]
        setenforce 0Copy to clipboard

        # Copy inceptionv3.tflite to inceptionv3_uint8.tflite
        cp /opt/inceptionv3.tflite /opt/inceptionv3_uint8.tfliteCopy to clipboard

        # Setup Wayland Display environment
        export XDG_RUNTIME_DIR=/dev/socket/weston && export WAYLAND_DISPLAY=wayland-1Copy to clipboard

        # Run a classification sample app
        gst-ai-classification --ml-framework=2Copy to clipboard

    - Default model path:
                            /opt/inceptionv3\_uint8.tflite
    - Default label path: /opt/classification.labels
2. To run the sample application using a custom classification model, use the
                    following arguments:
    - `--model`
    - `--labels`

    For
                    example:

        gst-ai-classification --ml-framework=2 --model=/opt/model.tflite --labels=/opt/classification.labelsCopy to clipboard
3. To stop the use case, press CTRL+C.

The sample application, when running, displays the camera stream on the connected
                monitor with inference results overlaid on the frame.

**Parent Topic:** [Getting started](https://docs.qualcomm.com/doc/80-70014-54/topic/getting-started.html)

Last Published: Jul 12, 2024

[Previous Topic
Getting started](https://docs.qualcomm.com/bundle/publicresource/80-70014-54/topics/getting-started.md) [Next Topic
Run a TensorFlow Lite model using a native TensorFlow Lite sample application](https://docs.qualcomm.com/bundle/publicresource/80-70014-54/topics/run-a-tensorflow-lite-model-using-a-native-tensorflow-lite-sample-application.md)