Skip to main content
This article applies to these versions of LandingLens:
LandingLensLandingLens on Snowflake
LandingEdge has a Custom Processing tool that automatically runs custom scripts before or after an image goes through inference. Custom Processing supports C# and Python scripts. The two Custom Processing options are:
  • Image Processing: LandingEdge runs the script before the image goes through inference.
  • Results Processing: LandingEdge runs the script after the images goes through inference.

Set Up Custom Processing

To add custom scripts to LandingEdge:
  1. Click Edit next to Image Processing or Results Processing. Custom Processing
  2. Select C# or Python from the drop-down menu, depending on the type of script you have.
  3. Replace the instructions in the large field with your custom script.
  4. Click Save. Save Script
  5. The Log Messages field displays a success message if the script is accepted. If you received an error in this field, please check your script and try again. Success Message
  6. Click Done.

Run Images Through Two Inspection Points

  • Script type: Results processing
  • Model type: Classification
  • Language: Python
Use this script to run an image through a second Inspection Point if a certain class is predicted in the first Inspection point. The class predicted by the second Inspection Point can override the class predicted by the first Inspection Point. This process is sometimes called “model-chaining” or “daisy-chaining”, because you are programmatically chaining models together. Here is the sample script. To see a use case, go to Use Case for Running Images Through Two Inspection Points.
The table below describes the placeholders that you will need to update when using this script.

Use Case for Running Images through Two Inspection Points

Let’s say you work for an automatic dog door company, and you want your model to detect dogs and puppies so that when a dog or puppy approaches the dog door, the door will automatically open. Your model has these classes: Not Dog, Dog, and Puppy. You can use the “daisy-chaining” script below to solve this use case. This is how the script works:
  • The image goes through the first Inspection Point.
  • The model in that Inspection Point predicts a class.- If the prediction is “Not Dog”, the image is not sent to a Second Inspection Point.
  • If the prediction is “Dog”, the image is sent to a second Inspection Point called “puppy-inspection” to check if the dog is a puppy.- If the second Inspection Point also predicts a dog, the class stays as “Dog”.
  • If the second Inspection Point predicts a puppy, the class is overridden to “Puppy”.
Here is the Python script for this use case:

Override the Class Name, Confidence Score, and Index

  • Script type: Results processing
  • Model type: Classification
  • Language: Python
Use this script to override the class name and confidence score of a model’s prediction. For example, use the script to override the final predictions based on the model’s results and other logic you’d like to add. Here is the sample script:
The table below describes the placeholders that you will need to update when using this script.

Add Metadata to Images

The ability to add metadata to images through scripting is available in LandingEdge v2.3.93 and later.
  • Script type: Results processing
  • Model type: Any
  • Language: Python
If you save images to LandingLens (by enabling Upload Results to LandingLens), you can see the image metadata on the Deploy page (Deploy > Self-Hosted Deployment > Inspection Point > open image). This metadata is only accessible in LandingLens, and isn’t embedded in the image. You can run a script to customize the values for the following metadata
  • Image ID
  • Inspection Station ID
  • Location ID
script_metadata Here is the sample script:
The table below describes the placeholders that you will need to update when using this script.

Skip Saving Certain Images

The ability to skip saving certain images through scripting is available in LandingEdge v2.4.89 and later.
  • Script type: Results processing
  • Model type: Any
  • Language: C#
If you save images to LandingLens (by enabling Upload Results to LandingLens), you can run a script to skip saving certain images. Here is the sample script:

Read Out Raw Scores from a Classification Model

The ability to read out raw scores through scripting is available in LandingEdge v2.5.10 and later.
  • Script type: Results processing
  • Model type: Classification
  • Language: C#
This sample script allows you to read out the raw scores from a Classification model. This script also includes AllClasses, which is a Dictionary with the class index as the key. The AllClasses Dictionary provides access to all names and indices of all classes in the model, so class information can be retrieved with AllClasses[index]. Here is the sample C# post-processing script for reading out the raw scores from a Classification model:
script_rawscores

Return Class Name for Object Detection Models

  • Script type: Results processing
  • Model type: Object Detection
  • Language: Python and C#
Let’s say you are using LandingEdge to run inference with an Object Detection model and sending the results to a Programmable Logic Controller (PLC). You want LandingEdge to send the name of the predicted class, but that action is only supported for Classification models. LandingEdge doesn’t directly support sending the class name for Object Detection models because there could be multiple objects and classes detected in each image. When it’s only possible for one object to be detected (like with Classification models), then the process is straightforward. As a workaround, you can use the C# and Python scripts below to:
  1. First, determine which box (the bounding box of the prediction around the object) has the highest confidence score.
  2. Then, return the class name of the box with the highest confidence score.
The scripts can be customized to use different criteria to determine which class is sent.

C# Script

Here is the sample C# script for returning the class name of the prediction with the highest confidence score:

Python Script

Here is the sample Python script for returning the class name of the prediction with the highest confidence score: