Jump to content

GstInference/Example pipelines with hierarchical metadata: Difference between revisions

no edit summary
(Created page with "This section will provide example pipelines for the platforms supported by GstInference, using the hierarchical metadata included since v0.7. It includes pipelines with all th...")
 
No edit summary
Line 1: Line 1:
This section will provide example pipelines for the platforms supported by GstInference, using the hierarchical metadata included since v0.7. It includes pipelines with all the supported backends and architectures on each platform. You can jump to an specific example by clicking on the following tables:
<noinclude>
{{GstInference/Head|previous=Example pipelines|next=Example pipelines/NANO|title=GstInference GStreamer pipelines on PC}}
</noinclude>
<!-- If you want a custom title for the page, un-comment and edit this line:
{{DISPLAYTITLE:GstInference - <descriptive page name>|noerror}}
-->
= Sample pipelines =
The following section contains a tool for generating simple GStreamer pipelines with one model of a selected architecture using our hierarchical inference metadata. If you are using and older version, you chan check the legacy pipelines section. Please make sure to check the documentation to understand the property usage for each element.
 
The required elements are:
* Backend
* Model
* Model location
* Labels
* Source
* Sink
 
The optional elements include:
* inferencefilter
* inferencrop
* inferenceoverlay 
 
[[File:Inference example.png|1000px|thumb|center|Detection with new metadata]]
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}
 
.button {
  background-color: #008CBA;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
 
input[type=text], select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
}
 
label {
  padding: 12px 12px 12px 0;
  display: inline-block;
}
 
input[type=submit] {
  background-color: #4CAF50;
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  float: right;
}
 
input[type=submit]:hover {
  background-color: #45a049;
}
 
.container {
  border-radius: 5px;
  background-color: lightcyan;
  padding: 20px;
}
 
.col-25 {
  float: left;
  width: 25%;
  margin-top: 6px;
}
 
.col-50 {
  float: left;
  width: 50%;
  margin-top: 6px;
}
 
.col-75 {
  float: left;
  width: 75%;
  margin-top: 6px;
}
 
/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}
 
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .col-25, .col-50, .col-75, input[type=submit] {
    width: 100%;
    margin-top: 0;
  }
}
 
// Material Select Initialization
$(document).ready(function() {
$('.mdb-select').materialSelect();
});
 
</style>
</head>
<body>
 
<h2>Pipeline generator</h2>
<p>The following tool will provide simple pipelines according to the selected elements.</p>
 
<div class="container">
  <form action="/action_page.php" id="gen_form">
    <div class="row">
      <div class="col-25">
        <label for="platform">Platform</label>
      </div>
      <div class="col-75">
        <select id="platform" name="platform" onchange="dynamic_platform_dropdown(this.options[this.selectedIndex].value)">
          <option value="" disabled selected>Select your platform</option>
          <option value="pc">PC</option>
          <option value="jetson">Jetson</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="backend">Backend</label>
      </div>
      <div class="col-75">
        <select id="backend" name="backend" onchange="backend_selection(this.options[this.selectedIndex].value)">
          <option value="" disabled selected>Select your backend</option>
          <option value="tensorflow">TensorFlow</option>
          <option value="tflite">TFLite</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="model_menu">Model</label>
      </div>
      <div class="col-75">
        <select id="model" name="model" onchange="model_selection()">
          <option value="" disabled selected>Select your architecture</option>
          <option value="inceptionv1">Inceptionv1</option>
          <option value="inceptionv2">Inceptionv2</option>
          <option value="inceptionv3">Inceptionv3</option>
          <option value="inceptionv4">Inceptionv4</option>
          <option value="mobilenetv2">MobileNetv2</option>
          <option value="facenetv1">FaceNet</option>
          <option value="tinyyolov2">TinyYolov2</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="input_layer">Input layer</label>
      </div>
      <div class="col-75">
        <input type="text" id="inputlayer" name="inputlayer" placeholder="Input layer..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="output_layer">Output layer</label>
      </div>
      <div class="col-75">
        <input type="text" id="outputlayer" name="outputlayer" placeholder="Output layer..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="output_layer">Model location</label>
      </div>
      <div class="col-75">
        <input type="text" id="model_location" name="model_location" placeholder="Path to model..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="output_layer">Labels</label>
      </div>
      <div class="col-75">
        <input type="text" id="labels" placeholder="Path to labels file..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="input_source">Source</label>
      </div>
      <div class="col-25">
        <select id="source" name="source">
          <option value="" disabled selected>Select your source</option>
          <option value=" multifilesrc">Image file</option>
          <option value=" filesrc">Video file</option>
          <option value=" v4l2src">Camera stream (v4l2)</option>
        </select>
      </div>
      <div class="col-50">
        <input type="text" id="source_location" placeholder="Source location">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="sink">Sink</label>
      </div>
      <div class="col-75">
        <select id="sink">
          <option value="" disabled selected>Select your sink</option>
          <option value=" fakesink" >fakesink</option>
          <option value=" videoconvert ! xvimagesink sync=false async=false qos=false">xvimagesink</option>
        </select>
      </div>
    </div>
  <h3>Optional utilites</h3>
  <p>The following elements are optional yet very useful. Check the documentation for more details on their properties.</p>
    <div class="row">
      <div class="col-25">
        <input type="checkbox" id="en_inferencefilter" onchange="enable_filter()">
        <label for="en_inferencefilter">Inference Filter</label>
      </div>
      <div class="col-75">
        <input type="text" id="filter_class_id" placeholder="Filter class id.."  disabled="true">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <input type="checkbox" id="en_inference_overlay" onchange="enable_overlay()">
        <label for="en_inference_overlay">Inference Overlay</label>
      </div>
      <div class="col-25">
        <input type="text" id="thickness" placeholder="Thickness" disabled="true">
      </div>
      <div class="col-25">
        <input type="text" id="fontscale" placeholder="Fontscale" disabled="true">
      </div>
      <div class="col-25">
        <select id="style" name="style" disabled=true>
          <option value="" disabled selected>Pick a style</option>
          <option value="0">Classic</option>
          <option value="1">Dotted</option>
          <option value="2">Dashed</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <input type="checkbox" id="en_inferencecrop" onchange="enable_crop()">
        <label for="en_inferencecrop">Inference Crop</label>
      </div>
      <div class="col-25">
        <input type="text" id="aspect_ratio" placeholder="Aspect ratio" disabled="true">
      </div>
    </div>
    <div class="row">
    <button type="button" class="button" onclick="reset_all()">Reset</button>
    <button type="button" class="button" onclick="print()">Generate!</button>
    </div>
  </form>
</div>
 
<!-- **********************  Variables and dicts ******************************** -->
 
<script>
var src = "";
var model = "";
var model_props = "";
var tee = "";
var filter = "";
var crop = "";
var overlay = "";
var sink = "";
 
var input_layers = {
  inceptionv1: "input",
  inceptionv2: "input",
  inceptionv3: "input",
  inceptionv4: "input",
  mobilenetv2: "input",
  resnet50v1: "input_tensor",
  tinyyolov2: "input/Placeholder",
  tinyyolov3: "inputs",
  facenetv1: "input"
};
 
 
var output_layers = {
  inceptionv1: "InceptionV1/Logits/Predictions/Reshape_1",
  inceptionv2: "Softmax",
  inceptionv3: "InceptionV3/Predictions/Reshape_1",
  inceptionv4: "InceptionV4/Logits/Predictions",
  mobilenetv2: "MobilenetV2/Predictions/Reshape_1",
  resnet50v1: "softmax_tensor",
  tinyyolov2: "add_8",
  tinyyolov3: "output_boxes",
  facenetv1: "output"
};
 
var model_names = {
  inceptionv1: "graph_inceptionv1_tensorflow.pb",
  inceptionv2: "graph_inceptionv2_tensorflow.pb",
  inceptionv3: "graph_inceptionv3_tensorflow.pb",
  inceptionv4: "graph_inceptionv4_tensorflow.pb",
  mobilenetv2: "graph_mobilenetv2_tensorflow.pb",
  resnet50v1: "graph_resnetv1_tensorflow.pb",
  tinyyolov2: "graph_tinyyolov2_tensorflow.pb",
  tinyyolov3: "graph_tinyyolov3_tensorflow.pb",
  facenetv1: "graph_facenetv1_tensorflow.pb"
};
 
var label_files = {
  inceptionv1: "imagenet_labels.txt",
  inceptionv2: "imagenet_labels.txt",
  inceptionv3: "imagenet_labels.txt",
  inceptionv4: "imagenet_labels.txt",
  mobilenetv2: "imagenet_labels.txt",
  resnet50v1: "imagenet_labels.txt",
  tinyyolov2: "labels.txt",
  tinyyolov3: "labels_ty3.txt",
  facenetv1: "imagenet_labels.txt"
};
 
/**********************************************************************
* General
***********************************************************************/
function reset_all() {
  document.getElementById("gen_form").reset();
  backend = "";
  src = "";
  model = "";
  model_props = "";
  tee = "";
  filter = "";
  crop = "";
  overlay = "";
  sink = "";
  disable_element("filter_class_id");
}
 
function disable_element(element) {
  document.getElementById(element).disabled=true;
  document.getElementById(element).value=null;
}
 
function enable_element(element) {
  document.getElementById(element).disabled=false;
}
 
function search_option(child_id, label, parent, mode) {
  var done="false";
  var selectobject = document.getElementById(parent);
  for (var i=0; i<selectobject.length; i++) {
      if (selectobject.options[i].value == child_id) {
        if(mode == "remove") {
          selectobject.remove(i);
        }
        done="true";
      }
  }
  if (done =="false") {
    if (mode == "add") {
      var new_option = document.createElement("option");
      new_option.text = label;
      new_option.value = child_id;
      document.getElementById(parent).appendChild(new_option);
    }
  }
}
 
/**********************************************************************
* Elements selection
***********************************************************************/
function dynamic_platform_dropdown(platform) {
  reset_all();
  document.getElementById("platform").value = platform;
 
  if (platform == "pc") {
    search_option("ncsdk","NCSDK","backend","add");
    search_option(" nvarguscamerasrc","nvarguscamerasrc","source","remove");
    search_option(" videoconvert ! 'video/x-raw,format=I420' ! nvvidconv ! nvoverlaysink","nvoverlaysink","sink","remove");
  } else {
    search_option("ncsdk","NCSDK","backend","remove");
    search_option(" nvarguscamerasrc","nvarguscamerasrc","source","add");
    search_option(" videoconvert ! 'video/x-raw,format=I420' ! nvvidconv ! nvoverlaysink","nvoverlaysink","sink","add");
  }
}
 
function backend_selection(backend) {
  var option_rn = document.createElement("option");
 
  switch (backend)
  {
    case "tensorflow" :
      search_option("tinyyolov3","TinyYolov3","model","add");
      search_option("resnet50v1","Resnet50V1","model","add");
      if( document.getElementById("model").value != "") {
        document.getElementById("inputlayer").value = input_layers[document.getElementById("model").value];
        document.getElementById("outputlayer").value = output_layers[document.getElementById("model").value];
      }
      enable_element("inputlayer");
      enable_element("outputlayer");
      break;
    case "tflite" :
      search_option("tinyyolov3","TinyYolov3","model","add");
      search_option("resnet50v1","Resnet50V1","model","add");
      disable_element("inputlayer");
      disable_element("outputlayer");
      break;
    case "ncsdk":
      search_option("tinyyolov3","TinyYolov3","model","remove");
      search_option("resnet50v1","Resnet50V1","model","remove");
      disable_element("inputlayer");
      disable_element("outputlayer");
      break;
  }
}
 
function model_selection() {
  if( document.getElementById("backend").value == "tensorflow") {
    document.getElementById("inputlayer").value = input_layers[document.getElementById("model").value];
    document.getElementById("outputlayer").value = output_layers[document.getElementById("model").value];
  }
  document.getElementById("model_location").value = model_names[document.getElementById("model").value];
  document.getElementById("labels").value = label_files[document.getElementById("model").value];
}
 
function crop_selection() {
  crop = " inferencecrop aspect-ratio=" + document.getElementById("aspect_ratio").value + " ! ";
}
 
function model_props_selection() {
  if (model != "") {
    model_props = " name=net model-location=" + document.getElementById("model_location").value + " backend=" + document.getElementById("backend").value + " labels=\"$(cat " +document.getElementById("labels").value + ")\"";
 
    if (backend == "tensorflow") {
      model_props = model_props + " backend::input-layer=" + document.getElementById("inputlayer").value + " backend::output-layer=" + document.getElementById("outputlayer").value;
    }
  } else {
    model_props = "";
  }
}
 
// TODO: modify for platform
function tee_selection() {
  if (model != "") {
    switch (platform) {
      case "jetson":
        tee = " tee name=t t. ! nvvidconv !  queue ! net.sink_model t. ! nvvidconv !  video/x-raw,format=RGBA ! queue ! net.sink_bypass net.src_model";
      break;
      case "pc":
        tee = " tee name=t t. ! queue ! videoconvert ! videoscale !  net.sink_model t. ! queue ! videoconvert ! net.sink_bypass  net.src_model !";
      break;
      default:
        tee = "";
      break;
    }
  } else {
    tee = "";
  }
}
 
function jetson_src_selection() {
  switch(src) {
    case " multifilesrc":
      src = src + " location=" + document.getElementById("source_location").value + " start-index=0 stop-index=0 loop=true ! jpegparse ! nvjpegdec ! 'video/x-raw' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvvidconv ! queue !";
    break;
    case " filesrc":
      src = src + " location=" + document.getElementById("source_location").value + " qtdemux name=demux ! h264parse ! omxh264dec ! nvvidconv ! queue !";
    break;
    case " v4l2src":
      src = src + " device=" + document.getElementById("source_location").value + " ! nvvidconv ! queue !";
    break;
    case " nvarguscamerasrc":
      src = src + " sensor-id=0 ! 'video/x-raw(memory:NVMM), format=(string)NV12' ! nvvidconv ! queue !";
    break;
    default:
      src = "";
    break;
  }
}
 
function pc_src_selection() {
  switch(src) {
    case " multifilesrc":
      src = src + " location=" + document.getElementById("source_location").value + " start-index=0 stop-index=0 loop=true ! jpegparse ! jpegdec ! videoconvert ! videoscale ! queue !";
    break;
    case " filesrc":
      src = src + " location=" + document.getElementById("source_location").value + " ! decodebin ! videoconvert ! videoscale ! queue !";
    break;
    case " v4l2src":
      src = src + " device=" + document.getElementById("source_location").value + " ! videoconvert ! videoscale ! queue !";
    break;
    default:
      src = "";
    break;
  }
}
 
function src_props_selection() {
  switch(platform) {
    case "pc":
      pc_src_selection();
    break;
    case "jetson":
      jetson_src_selection();
    break;
  }
 
}
 
/**********************************************************************
* Optional utilities - enable
***********************************************************************/
 
function enable_overlay() {   
  var checkbox = document.getElementById('en_inference_overlay');
  if(checkbox.checked == true) {
    enable_element("thickness");
    enable_element("fontscale");
    enable_element("style");
    overlay = " fakesink net.src_bypass ! queue ! inferenceoverlay !";
  } else {
    disable_element("thickness");
    disable_element("fontscale");
    disable_element("style");
    overlay = "";
  }
}
 
function enable_filter() {   
  var checkbox = document.getElementById('en_inferencefilter');
  if(checkbox.checked == true) {
    enable_element("filter_class_id");
    filter = " inferencefilter";
  } else {
    disable_element("filter_class_id");
    filter = "";
  }
}
 
function enable_crop() {   
  var checkbox = document.getElementById('en_inferencecrop');
  if(checkbox.checked == true) {
    enable_element("aspect_ratio");
    crop = " inferencecrop";
  } else {
    disable_element("aspect_ratio");
    crop = "";
  }
}
 
/**********************************************************************
* print final pipeline
***********************************************************************/
 
function print() {
  platform = document.getElementById("platform").value;
  backend = document.getElementById("backend").value;
  model = document.getElementById("model").value;
  src = document.getElementById("source").value;
  sink = document.getElementById("sink").value;
 
  if(model != "") {
    model_props_selection();
  }
 
  if(src != "") {
  tee_selection();
  src_props_selection(); 
  }
 
 
  if(overlay != "") {
    overlay = " fakesink net.src_bypass ! queue ! inferenceoverlay !";
    var thickness= document.getElementById("thickness").value;
    var fontscale=document.getElementById("fontscale").value;
    var style=document.getElementById("style").value;
 
    if(thickness != "") {
      overlay = overlay + " thickness=" + thickness;
    }
    if(fontscale != "") {
      overlay = overlay + " fontscale=" + fontscale;
    }
    if(style != "") {
      overlay = overlay + " style=" + style;
    }
    overlay = overlay + " !";
  }
  if(filter != "") {
    filter = " inferencefilter";
    if(document.getElementById("filter_class_id").value != "") {
      filter = filter + " filter-class=" + document.getElementById("filter_class_id").value + " !";
    } else {
      filter = filter + " !";
    }
  }
   
  if(crop != "") {
    crop = " inferencecrop";
    if(document.getElementById("aspect_ratio").value != "") {
      crop = crop + " aspect-ratio=" + document.getElementById("aspect_ratio").value + " !";
    } else {
      crop = crop + " !";
    }
  }
  document.getElementById("new_pipeline").value = "gst-launch-1.0 " + model + model_props + src + tee + filter + crop + overlay + sink;
}
 
</script>
<textarea id="new_pipeline" name="Text1" cols="140" rows="5"></textarea>
 
</body>
</html>
 
 
= Advanced pipelines =
 
<noinclude>
{{GstInference/Foot|Example pipelines|Example pipelines/NANO}}
</noinclude>
352

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.