Skip to content

Commit 8fe34e2

Browse files
[SDK] add 'save_probabilities' field to a sliding window inference for detection models
[Guide] slidign window inference tutorial
1 parent 53f7b8a commit 8fe34e2

File tree

28 files changed

+140
-159
lines changed

28 files changed

+140
-159
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ remote.sh
2424
/plugins.txt
2525
*.pth
2626
docs/_build
27-
*log_*.txt
27+
*log_*.txt
28+
docs/_build/*
29+
30+
internal/tests/flt_format_insurance/*

help/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ For now we have the following resources available:
3434
* [Custom data pipeline: upload -> auto labeling jobs -> move labeled data to "secret" project](./jupyterlab_scripts/src/tutorials/11_custom_data_pipeline/custom_data_pipeline.ipynb)
3535
* [Filter images in different projects and combine results into a new project](./jupyterlab_scripts/src/tutorials/12_filter_and_combine_images/filter_combine_images.ipynb)
3636
* [How to apply NN (UNet/YOLO/Mask-RCNN) to the image from sources](./jupyterlab_scripts/src/tutorials/13_nn_inference_from_sources/README.md)
37+
* [Apply NN to image parts (slidign window inference)](./tutorials/09_sliding_window/readme.md)
38+
3739

3840
#### Cookbooks
3941

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/01.png
2+
/02.png
3+
/03.png
4+
/04.png
5+
/original copy.png
6+
/original.png
Loading
212 KB
Loading
Loading
181 KB
Loading
Loading
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Sliding Window Inference
2+
3+
Task description:
4+
1. all our images have the same resolution
5+
2. we would like to split images to 4 parts, apply NN to these parts and combine results back to single image.
6+
7+
Supervisely supports several inference modes, including Sliding Window. It's useful for getting inference results on larger images without modifying them during the process. Currently, there are 2 ways in which this method can be used.
8+
9+
## Sliding Window Inference mode for Neural Networks
10+
11+
This is the first and most straightforward method for this type of task. You only need to add a Neural Network model to your account and run it with the appropriate settings.
12+
13+
### Example
14+
15+
Let's start by adding **YOLO v3** model to our account from the Explore page. You can navigate here from the *Explore* page → *Models* or from the *Neural Networks* via the *+ Add* button at the top of that page.
16+
17+
![](./add_yolo.png)
18+
19+
Once we're done that, we can go forward and try the model on our test image. For the purposes of this tutorial it's already uploaded to the platform as a *Dogs* containing a single dataset with a single file in it.
20+
21+
![](./dogs.jpg)
22+
23+
Now we navigate to the Neural networks page and press the *Test* button.
24+
25+
![](./test_run.png)
26+
27+
On the next page, we need to select the correct agent node and input project, type in the result title, select and adjust the NN cofig to fit our purposes.
28+
![](./si_merge.png)
29+
30+
```json
31+
{
32+
"mode": {
33+
"name": "sliding_window_det",
34+
"save": false,
35+
"window": {
36+
"width": 1200,
37+
"height": 900
38+
},
39+
"nms_after": {
40+
"enable": true,
41+
"iou_threshold": 0.4,
42+
"confidence_tag_name": "confidence"
43+
},
44+
"class_name": "sl_window",
45+
"model_tags": {
46+
"add_suffix": "_yolo",
47+
"save_names": "__all__"
48+
},
49+
"min_overlap": {
50+
"x": 0,
51+
"y": 0
52+
},
53+
"model_classes": {
54+
"add_suffix": "_yolo",
55+
"save_classes": "__all__"
56+
}
57+
},
58+
"model": {
59+
"gpu_device": 0,
60+
"num_processes": 1,
61+
"confidence_tag_name": "confidence",
62+
"min_confidence_threshold": 0.5
63+
}
64+
}
65+
```
66+
67+
In this particular case, we are only interested in data located at the corners of our image. Also, the image in question is rather large, 2400x1800px. So what we can do in this case, is to set the sliding window mode to 1200X900 - this will force the neural network to treat the image as 4 images of that size and combine the results afterwards.
68+
69+
![](./4_parts_explanation/result.png)
70+
71+
![](./dogs_1.png)
72+
73+
Once the task has been processed, we can view the results:
74+
75+
![](./dogs_sw_inf.png)
76+
77+
As you can see, the model performed as expected, performing accurately in the corners of the image. This method is fast and easy to use in simple cases.
78+
79+
## Sliding Window Inference using Split and Merge scripts
80+
81+
This method is a bit more involved than the previous one, but it provides a bit more control over the end results, if that's what you need.
82+
83+
### Example
84+
85+
Let's use the same source image and the same **YOLO v3** model as we did before. However, our first step will be quite different: we need to add the custom [Split and Merge scripts](https://github.com/supervisely/supervisely/tree/master/plugins/python/src/examples/001_image_splitter) to our account. Please follow the tutorial provided in the link. Once you're done, you'll be able to call the *Split* script from the Project Context Menu → Run Python Script → Split. This will bring up the following settings window:
86+
87+
![](./split_settings.png)
88+
89+
Let's apply the same window parameters we used in the first example. As a result, the source image will be split in 4 1200x900 sized parts:
90+
91+
![](./split_dogs_raw.png)
92+
93+
Here's what the 3 other images look like:
94+
95+
![](./split_dogs_raw_other_parts.png)
96+
97+
Now we can run our Neural Network on these images. Please note that in this case, we need to use the Full Image mode, as we already split the source image in 4 in the previous step.
98+
99+
![](./fi_merged.png)
100+
101+
After the model is done processing the images, let's view the results:
102+
103+
![](./split_dogs_inf.png)
104+
105+
At this step we can adjust the predictions on the individual images. For the purposes of comparison, we won't do it in in this example, but the option to do so is still there. Instead, we'll just merge the images back together using the *Merge script*:
106+
107+
![](./merge_settings.png)
108+
109+
Now let's view what we got as a result:
110+
111+
![](./split_dogs_inf_merged.png)
112+
113+
As you can see, in this case the end results are pretty similar to the previous method, as we skipped adjusting individual annotations a couple steps agp and used the same settings across both examples.
114+
115+
You can choose which method you prefer based on your input images and desired results.
210 KB
Loading
Loading
Loading
Loading
Loading
Loading
109 KB
Loading

plugins/nn/deeplab_v3plus/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-deeplab-v3-plus:6.0.21
1+
nn-deeplab-v3-plus:6.0.22

plugins/nn/icnet/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-icnet:6.0.21
1+
nn-icnet:6.0.22
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-mask-rcnn-keras-tf:6.0.21
1+
nn-mask-rcnn-keras-tf:6.0.22

plugins/nn/pspnet/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-psp-net:6.0.19
1+
nn-psp-net:6.0.20

plugins/nn/resnet_classifier/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-resnet-class:6.0.21
1+
nn-resnet-class:6.0.22
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-tf-obj-det:6.0.21
1+
nn-tf-obj-det:6.0.22

plugins/nn/unet_v2/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-unet-v2:6.0.21
1+
nn-unet-v2:6.0.22

plugins/nn/unet_v2_cuda_10_1/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-unet-v2-cuda-10-1:6.0.21
1+
nn-unet-v2-cuda-10-1:6.0.22

plugins/nn/yolo_v3/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nn-yolo-v3:6.0.21
1+
nn-yolo-v3:6.0.22

plugins/python/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-runner:6.0.26
1+
python-runner:6.0.27

plugins/python/src/seed/011_download_as_pointcloud_annotations/delme.json

-148
This file was deleted.

supervisely_lib/nn/hosted/inference_modes_schemas/sliding_window_det.json

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@
168168
},
169169
"model_tags": {
170170
"$ref": "#/definitions/renamer"
171+
},
172+
"save_probabilities": {
173+
"type": "boolean"
171174
}
172175
}
173176
}

0 commit comments

Comments
 (0)