Last updated
Last updated
Supervisely instance version >= 6.12.13 Supervisely SDK version >= 6.73.272\
Supervisely SDK is used only for releasing the application. The application will be using the sly_sdk
module as supervisely
in the app runtime, so it must be present in the repository for application to work.
Developing a in-browser custom app for the Labeling Tool can be useful in the following cases:
When you need to combine manual labeling and the algorithmic post-processing of the labels in real-time.
When you need to validate created labels for some specific rules in real-time.
In this tutorial, we'll learn how to develop an application that will process masks in real-time while working with the Image Labeling Tool. The processing will be triggered automatically after the mask is created with the Brush tool (after releasing the left mouse button). The demo app will also have settings for enabling / disabling the processing and adjusting the mask processing settings.
We will go through the following steps:
Prepare UI widgets and the application's layout. Handle the events. Prepare the config.json file. Process the mask. Implement the processing function. Release the app and run it in Supervisely.\
Everything you need to reproduce : source code and additional app files. Another example of the app that processes the masks in real-time can be found
To be able to change the app's settings we need to add UI widgets to the app's layout. So, we'll need two widgets:
Switch widget for enabling / disabling the processing
Slider widget for adjusting the mask processing settings
Only widgets that are present in sly_sdk.app.widgets
can be used for such applications. But you should import them from supervisely.app.widgets
in the app's code.
The widget_id
argument is required. It should be unique for each widget in the app.
Now, our widgets are ready and we can create the app's layout:
Now, we need to handle the events that will be triggered by the Labeling Tool. In this tutorial, we'll be using only one event, when the left mouse button is released after drawing a mask. So, catching the event will is pretty simple:
That's it! Our function will receive the dict object with event data and that's all we need to process the mask. In our case the data will contain a single key:
type
: client_side_app
- it's a key that tells the platform that this app is an in-browser app.
integrated_into
: [image_annotation_tool
] - it's a key that tells the platform that this app should be integrated into the Image Labeling Tool.
gui_folder_path
: app
- it is a key that tells the platform where the app's layout is located. It can be any non-conflicting path. It will only be used when releasing the application.
main_script
: src/main.py
- it's a key that tells the platform where the main script of the app is located. This fhile should contain the app
variable of the WebPyApplication
type.
src_dir
: src
- it's a key that tells the platform where the source code of the app is located. All the modules that you import in the main script should be located in this directory.
So, it will allow us to run the application directly in the Image Labeling Tool.
And now we're ready to implement the mask processing. But first, let's do some checks to make sure that we need to use the processing of the mask.
So, if the processing is turned off or the current geometry version of the figure less or equal to the last version we set, then we don't need to process the mask and we'll just exit the function. And now, let's finally process the mask!
Let's take a closer look at the process function:
We're retrieving the geometry from the figure object.
We're processing the mask in the process function.
We're updating the figure geometry directly in the labeling tool.
So, we already have the code for all the application's logic. But we still don't have the code for the processing function. In this tutorial, we'll be using a simple mask transformation just for demonstration purposes. But you can implement any logic you want.
Let's take a closer look at the process function:
We're reading the dilation strength from the Slider widget.
We're converting the mask to the uint8 type since it cames as a boolean 2D array from the Event object.
We're returning a new mask.
After it's done, you can find your app in the Apps section of the platform and run it in the Labeling Tool. Follow the steps below to run the app in Supervisely:
Open Image Labeling Tool in Supervisely.
Select the Apps tab.
Find the application and click Run.
The app's UI will be opened in the right sidebar.
In this tutorial, we learned how to develop an in-browser application for the Image Labeling Tool. We learned how to use UI widgets, how to handle the events and how to process the mask. We also learned how to release the app and run it in Supervisely. We hope that this tutorial was helpful for you and you'll be able to use it as a reference for your application.
Now, when we're ready to start testing our app, we first need to prepare the config.json file, so our app can be launched directly in the Labeling Tool. You can find a lot of information using the config.json file . In this tutorial, we will pay attention to the specific keys in the file:
Now we can release it and run it in Supervisely. You can find a detailed guide on how to release the app , but in this tutorial, we'll just use the following command: