Batch Model Plugins

With the Batch Model custom plugin, you can add a quick way for users to run your model on their project assets.

When users click to run your plugin, you will get their assets, feed them to your model, and return the model's results as pre-annotations to their assets.

Creating a Batch Model Plugin

Following the steps outlined in this section, create a new plugin from the UI, choosing "Batch Model" as the plugin type.

For more information on what all of the fields do, you may check the Plugin Developer Documentation's main page.

In the "Class Names" section, enter the names of the classes used by your model. For example, if it detects cars, bikes, and trains using three different labeling tools, enter the three class names here.

In the "Default Config" section, enter JSON which will be shown to users by default in their Config JSON field when running the plugin. Users can input any freeform JSON in this field, and it will be passed to your callback function in the code as parameter.

Then, create and run a Python script using the BatchModelPlugin class you can find in our imerit-ango Python package under imerit_ango.plugins.

You will need to add the imerit-ango package to your Python environment by running

pip install imerit-ango

Here is the class's documentation, and an example:

BatchModelPlugin

Parameters:

  • id: string

    • The plugin's ID. You may obtain this ID from the plugin's information box in the Development section of the Plugin page.

  • secret: string

    • The plugin's secret. You can think of this as a private key you'll need to be able to connect your script to the plugin. You may obtain this secret from the plugin's information box in the Development section of the Plugin page.

  • callback: Callable[[str, dict], Tuple[str, BytesIO]]

    • The callback function. This function will be run whenever a user asks for your model to be run using this plugin. More on the callback function below.

Callback Function

Parameters:

  • **data: dict

    • projectId: string

      • The ID of the project for which the plugin was run.

    • categorySchema: dict

      • The label categories that have been passed to this plugin when the plugin is being run.

      • For example, when creating the plugin, if in the "Class Names" section you had input the classes "Vehicle" and "Person", and when running, if they were both mapped to existing labeling tools, this is what you would get as input here:

      [{'schemaId': '797ea755f5693c0dc902558', 'modelClass': 'Vehicle'}, {'schemaId': '797ea755f5693c0dc902558', 'modelClass': 'Person'}]
    • apiKey: str

    • orgId: str

    • runBy: str

      • The user ID of the user running the plugin.

    • session: str

    • logger: PluginLogger

    • batches: List[str]

    • configJSON: str

      • The config JSON your users will pass to you through the Config JSON text field when running the plugin. Warning: the JSON will be passed as a string so you will have to destringify it. Example code to obtain the original JSON as a Python object:

    def sample_callback(**data):
        config_str = data.get('configJSON')
        config = json.loads(config_str)

Returns:

  • message: string

    • A message to show users when the plugin finishes running.

Sample Python Script

In this script, we get the first 10 assets of the project. Then, for the sake of brevity, instead of running them through a model, we add a bounding box to each as pre-label, "simulating" the model's results. We then upload these annotations to the user's assets with a "To-Do" status as prelabels using the SDK.

Sample code:

For this example, we use the following default Config JSON:

{
  "dummy-bounding-box": {
    "x": 20, 
    "y": 30, 
    "width": 50, 
    "height": 60
  }
}

Running a Model using the Plugin

Your Python script needs to be running for users to be able to run your plugin.

Navigate to the project were you'd like to run the model. From the Settings tab, enter the Plugins section. Click Open on the Model plugin of interest.

From the dialog that pops up, map your classes to the model's classes, then click on Run.

Last updated