Skip to content

Commit 2fa5317

Browse files
committed
Add v2 doc for small object detection
1 parent e9acfb8 commit 2fa5317

File tree

2 files changed

+176
-34
lines changed

2 files changed

+176
-34
lines changed

articles/machine-learning/how-to-use-automl-small-object-detect.md

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ ms.service: machine-learning
77
ms.subservice: automl
88
ms.topic: how-to
99
ms.date: 10/13/2021
10-
ms.custom: sdkv1, event-tier1-build-2022
10+
ms.custom: sdkv2, event-tier1-build-2022
1111
---
1212

1313
# Train a small object detection model with AutoML (preview)
1414

15-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
15+
<todo phm: Check with Samantha is the title1 in the below selector is apprropriate>
16+
17+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
18+
> [!div class="op_single_selector" title1="Select the version of Azure Machine Learning CLI extension you are using:"]
19+
> * [v1](v1/how-to-use-automl-small-object-detect-v1.md)
20+
> * [v2 (current version)](how-to-use-automl-small-object-detect.md)
1621
1722
> [!IMPORTANT]
1823
> This feature is currently in public preview. This preview version is provided without a service-level agreement. Certain features might not be supported or might have constrained capabilities. For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
@@ -23,94 +28,122 @@ Typically, computer vision models for object detection work well for datasets wi
2328

2429
To help with this problem, automated ML supports tiling as part of the public preview computer vision capabilities. The tiling capability in automated ML is based on the concepts in [The Power of Tiling for Small Object Detection](https://openaccess.thecvf.com/content_CVPRW_2019/papers/UAVision/Unel_The_Power_of_Tiling_for_Small_Object_Detection_CVPRW_2019_paper.pdf).
2530

26-
When tiling, each image is divided into a grid of tiles. Adjacent tiles overlap with each other in width and height dimensions. The tiles are cropped from the original as shown in the following image.
31+
When tiling, each image is divided into a grid of tiles. Adjacent tiles overlap with each other in width and height dimensions. The tiles are cropped from the original as shown in the following image.
2732

2833
![Tiles generation](./media/how-to-use-automl-small-object-detect/tiles-generation.png)
2934

3035
## Prerequisites
3136

3237
* An Azure Machine Learning workspace. To create the workspace, see [Create workspace resources](quickstart-create-resources.md).
3338

34-
* This article assumes some familiarity with how to configure an [automated machine learning experiment for computer vision tasks](how-to-auto-train-image-models.md).
39+
* This article assumes some familiarity with how to configure an [automated machine learning experiment for computer vision tasks](how-to-auto-train-image-models.md).
3540

3641
## Supported models
3742

38-
Small object detection using tiling is currently supported for the following models:
39-
40-
* fasterrcnn_resnet18_fpn
41-
* fasterrcnn_resnet50_fpn
42-
* fasterrcnn_resnet34_fpn
43-
* fasterrcnn_resnet101_fpn
44-
* fasterrcnn_resnet152_fpn
45-
* retinanet_resnet50_fpn
43+
Small object detection using tiling is supported for all models supported by Automated ML for images for object detection task.
4644

4745
## Enable tiling during training
4846

49-
To enable tiling, you can set the `tile_grid_size` parameter to a value like (3, 2); where 3 is the number of tiles along the width dimension and 2 is the number of tiles along the height dimension. When this parameter is set to (3, 2), each image is split into a grid of 3 x 2 tiles. Each tile overlaps with the adjacent tiles, so that any objects that fall on the tile border are included completely in one of the tiles. This overlap can be controlled by the `tile_overlap_ratio` parameter, which defaults to 25%.
47+
To enable tiling, you can set the `tile_grid_size` parameter to a value like `'3x2'`; where 3 is the number of tiles along the width dimension and 2 is the number of tiles along the height dimension. When this parameter is set to `'3x2'`, each image is split into a grid of 3 x 2 tiles. Each tile overlaps with the adjacent tiles, so that any objects that fall on the tile border are included completely in one of the tiles. This overlap can be controlled by the `tile_overlap_ratio` parameter, which defaults to 25%.
5048

51-
When tiling is enabled, the entire image and the tiles generated from it are passed through the model. These images and tiles are resized according to the `min_size` and `max_size` parameters before feeding to the model. The computation time increases proportionally because of processing this extra data.
49+
When tiling is enabled, the entire image and the tiles generated from it are passed through the model. These images and tiles are resized according to the `min_size` and `max_size` parameters before feeding to the model. The computation time increases proportionally because of processing this extra data.
5250

53-
For example, when the `tile_grid_size` parameter is (3, 2), the computation time would be approximately seven times when compared to no tiling.
51+
For example, when the `tile_grid_size` parameter is `'3x2'`, the computation time would be approximately seven times when compared to no tiling.
5452

5553
You can specify the value for `tile_grid_size` in your hyperparameter space as a string.
5654

55+
<todo phm: see if we should use set_image_model here instead of parameter_space>
56+
57+
# [CLI v2](#tab/CLI-v2)
58+
59+
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
60+
61+
```yaml
62+
search_space:
63+
- model_name: "fasterrcnn_resnet50_fpn"
64+
tile_grid_size: "choice('3x2')"
65+
```
66+
67+
# [Python SDK v2 (preview)](#tab/SDK-v2)
68+
5769
```python
58-
parameter_space = {
59-
'model_name': choice('fasterrcnn_resnet50_fpn'),
60-
'tile_grid_size': choice('(3, 2)'),
61-
...
62-
}
70+
image_object_detection_job.extend_search_space(
71+
ImageObjectDetectionSearchSpace(
72+
model_name=Choice(['fasterrcnn_resnet50_fpn']),
73+
tile_grid_size=Choice(['3x2'])
74+
)
75+
)
6376
```
77+
---
6478

6579
The value for `tile_grid_size` parameter depends on the image dimensions and size of objects within the image. For example, larger number of tiles would be helpful when there are smaller objects in the images.
6680

6781
To choose the optimal value for this parameter for your dataset, you can use hyperparameter search. To do so, you can specify a choice of values for this parameter in your hyperparameter space.
6882

83+
<todo phm: need to update the CLI and SDK examples once changes from Nilesh and Madhu are in>
84+
85+
# [CLI v2](#tab/CLI-v2)
86+
87+
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
88+
89+
```yaml
90+
search_space:
91+
- model_name: "fasterrcnn_resnet50_fpn"
92+
tile_grid_size: "choice('2x1', '3x2', '5x3')"
93+
```
94+
95+
# [Python SDK v2 (preview)](#tab/SDK-v2)
96+
6997
```python
70-
parameter_space = {
71-
'model_name': choice('fasterrcnn_resnet50_fpn'),
72-
'tile_grid_size': choice('(2, 1)', '(3, 2)', '(5, 3)'),
73-
...
74-
}
98+
image_object_detection_job.extend_search_space(
99+
ImageObjectDetectionSearchSpace(
100+
model_name=Choice(['fasterrcnn_resnet50_fpn']),
101+
tile_grid_size=Choice(['2x1', '3x2', '5x3'])
102+
)
103+
)
75104
```
105+
---
106+
76107
## Tiling during inference
77108

78109
When a model trained with tiling is deployed, tiling also occurs during inference. Automated ML uses the `tile_grid_size` value from training to generate the tiles during inference. The entire image and corresponding tiles are passed through the model, and the object proposals from them are merged to output final predictions, like in the following image.
79110

80111
![Object proposals merge](./media/how-to-use-automl-small-object-detect/tiles-merge.png)
81112

82-
> [!NOTE]
113+
> [!NOTE]
83114
> It's possible that the same object is detected from multiple tiles, duplication detection is done to remove such duplicates.
84115
>
85116
> Duplicate detection is done by running NMS on the proposals from the tiles and the image. When multiple proposals overlap, the one with the highest score is picked and others are discarded as duplicates.Two proposals are considered to be overlapping when the intersection over union (iou) between them is greater than the `tile_predictions_nms_thresh` parameter.
86117
87-
You also have the option to enable tiling only during inference without enabling it in training. To do so, set the `tile_grid_size` parameter only during inference, not for training.
118+
You also have the option to enable tiling only during inference without enabling it in training. To do so, set the `tile_grid_size` parameter only during inference, not for training.
88119

89-
Doing so, may improve performance for some datasets, and won't incur the extra cost that comes with tiling at training time.
120+
Doing so, may improve performance for some datasets, and won't incur the extra cost that comes with tiling at training time.
90121

91-
## Tiling hyperparameters
122+
## Tiling hyperparameters
92123

93124
The following are the parameters you can use to control the tiling feature.
94125

95126
| Parameter Name | Description | Default |
96127
| --------------- |-------------| -------|
97-
| `tile_grid_size` | The grid size to use for tiling each image. Available for use during training, validation, and inference.<br><br>Tuple of two integers passed as a string, e.g `'(3, 2)'`<br><br> *Note: Setting this parameter increases the computation time proportionally, since all tiles and images are processed by the model.*| no default value |
128+
| `tile_grid_size` | The grid size to use for tiling each image. Available for use during training, validation, and inference.<br><br> Should be passed as a string in `'3x2'` format.<br><br> *Note: Setting this parameter increases the computation time proportionally, since all tiles and images are processed by the model.*| no default value |
98129
| `tile_overlap_ratio` | Controls the overlap ratio between adjacent tiles in each dimension. When the objects that fall on the tile boundary are too large to fit completely in one of the tiles, increase the value of this parameter so that the objects fit in at least one of the tiles completely.<br> <br> Must be a float in [0, 1).| 0.25 |
99130
| `tile_predictions_nms_thresh` | The intersection over union threshold to use to do non-maximum suppression (nms) while merging predictions from tiles and image. Available during validation and inference. Change this parameter if there are multiple boxes detected per object in the final predictions. <br><br> Must be float in [0, 1]. | 0.25 |
100131

101132

102133
## Example notebooks
103134

104-
See the [object detection sample notebook](https://github.com/Azure/azureml-examples/tree/main/python-sdk/tutorials/automl-with-azureml/image-object-detection/auto-ml-image-object-detection.ipynb) for detailed code examples of setting up and training an object detection model.
135+
<todo phm: this link in other docs is pointing to sdk-preview branch. needs to be updated>
136+
137+
See the [object detection sample notebook](https://github.com/Azure/azureml-examples/blob/main/sdk/jobs/automl-standalone-jobs/automl-image-object-detection-task-fridge-items/automl-image-object-detection-task-fridge-items.ipynb) for detailed code examples of setting up and training an object detection model.
105138

106139
>[!NOTE]
107-
> All images in this article are made available in accordance with the permitted use section of the [MIT licensing agreement](https://choosealicense.com/licenses/mit/).
140+
> All images in this article are made available in accordance with the permitted use section of the [MIT licensing agreement](https://choosealicense.com/licenses/mit/).
108141
> Copyright © 2020 Roboflow, Inc.
109142
110143
## Next steps
111144

112145
* Learn more about [how and where to deploy a model](/azure/machine-learning/how-to-deploy-managed-online-endpoints).
113-
* For definitions and examples of the performance charts and metrics provided for each job, see [Evaluate automated machine learning experiment results](how-to-understand-automated-ml.md).
146+
* For definitions and examples of the performance charts and metrics provided for each job, see [Evaluate automated machine learning experiment results](how-to-understand-automated-ml.md).
114147
* [Tutorial: Train an object detection model (preview) with AutoML and Python](tutorial-auto-train-image-models.md).
115148
* See [what hyperparameters are available for computer vision tasks](reference-automl-images-hyperparameters.md).
116-
*[Make predictions with ONNX on computer vision models from AutoML](how-to-inference-onnx-automl-image-models.md)
149+
*[Make predictions with ONNX on computer vision models from AutoML](how-to-inference-onnx-automl-image-models.md)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Use AutoML to detect small objects in images
3+
description: Set up Azure Machine Learning automated ML to train small object detection models.
4+
author: PhaniShekhar
5+
ms.author: phmantri
6+
ms.service: machine-learning
7+
ms.subservice: automl
8+
ms.topic: how-to
9+
ms.date: 10/13/2021
10+
ms.custom: sdkv1, event-tier1-build-2022
11+
---
12+
13+
# Train a small object detection model with AutoML (preview)
14+
15+
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
16+
17+
> [!IMPORTANT]
18+
> This feature is currently in public preview. This preview version is provided without a service-level agreement. Certain features might not be supported or might have constrained capabilities. For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
19+
20+
In this article, you'll learn how to train an object detection model to detect small objects in high-resolution images with [automated ML](concept-automated-ml.md) in Azure Machine Learning.
21+
22+
Typically, computer vision models for object detection work well for datasets with relatively large objects. However, due to memory and computational constraints, these models tend to under-perform when tasked to detect small objects in high-resolution images. Because high-resolution images are typically large, they are resized before input into the model, which limits their capability to detect smaller objects--relative to the initial image size.
23+
24+
To help with this problem, automated ML supports tiling as part of the public preview computer vision capabilities. The tiling capability in automated ML is based on the concepts in [The Power of Tiling for Small Object Detection](https://openaccess.thecvf.com/content_CVPRW_2019/papers/UAVision/Unel_The_Power_of_Tiling_for_Small_Object_Detection_CVPRW_2019_paper.pdf).
25+
26+
When tiling, each image is divided into a grid of tiles. Adjacent tiles overlap with each other in width and height dimensions. The tiles are cropped from the original as shown in the following image.
27+
28+
![Tiles generation](./media/how-to-use-automl-small-object-detect/tiles-generation.png)
29+
30+
## Prerequisites
31+
32+
* An Azure Machine Learning workspace. To create the workspace, see [Create workspace resources](quickstart-create-resources.md).
33+
34+
* This article assumes some familiarity with how to configure an [automated machine learning experiment for computer vision tasks](how-to-auto-train-image-models.md).
35+
36+
## Supported models
37+
38+
Small object detection using tiling is supported for all models supported by Automated ML for images for object detection task.
39+
40+
## Enable tiling during training
41+
42+
To enable tiling, you can set the `tile_grid_size` parameter to a value like (3, 2); where 3 is the number of tiles along the width dimension and 2 is the number of tiles along the height dimension. When this parameter is set to (3, 2), each image is split into a grid of 3 x 2 tiles. Each tile overlaps with the adjacent tiles, so that any objects that fall on the tile border are included completely in one of the tiles. This overlap can be controlled by the `tile_overlap_ratio` parameter, which defaults to 25%.
43+
44+
When tiling is enabled, the entire image and the tiles generated from it are passed through the model. These images and tiles are resized according to the `min_size` and `max_size` parameters before feeding to the model. The computation time increases proportionally because of processing this extra data.
45+
46+
For example, when the `tile_grid_size` parameter is (3, 2), the computation time would be approximately seven times when compared to no tiling.
47+
48+
You can specify the value for `tile_grid_size` in your hyperparameter space as a string.
49+
50+
```python
51+
parameter_space = {
52+
'model_name': choice('fasterrcnn_resnet50_fpn'),
53+
'tile_grid_size': choice('(3, 2)'),
54+
...
55+
}
56+
```
57+
58+
The value for `tile_grid_size` parameter depends on the image dimensions and size of objects within the image. For example, larger number of tiles would be helpful when there are smaller objects in the images.
59+
60+
To choose the optimal value for this parameter for your dataset, you can use hyperparameter search. To do so, you can specify a choice of values for this parameter in your hyperparameter space.
61+
62+
```python
63+
parameter_space = {
64+
'model_name': choice('fasterrcnn_resnet50_fpn'),
65+
'tile_grid_size': choice('(2, 1)', '(3, 2)', '(5, 3)'),
66+
...
67+
}
68+
```
69+
## Tiling during inference
70+
71+
When a model trained with tiling is deployed, tiling also occurs during inference. Automated ML uses the `tile_grid_size` value from training to generate the tiles during inference. The entire image and corresponding tiles are passed through the model, and the object proposals from them are merged to output final predictions, like in the following image.
72+
73+
![Object proposals merge](./media/how-to-use-automl-small-object-detect/tiles-merge.png)
74+
75+
> [!NOTE]
76+
> It's possible that the same object is detected from multiple tiles, duplication detection is done to remove such duplicates.
77+
>
78+
> Duplicate detection is done by running NMS on the proposals from the tiles and the image. When multiple proposals overlap, the one with the highest score is picked and others are discarded as duplicates.Two proposals are considered to be overlapping when the intersection over union (iou) between them is greater than the `tile_predictions_nms_thresh` parameter.
79+
80+
You also have the option to enable tiling only during inference without enabling it in training. To do so, set the `tile_grid_size` parameter only during inference, not for training.
81+
82+
Doing so, may improve performance for some datasets, and won't incur the extra cost that comes with tiling at training time.
83+
84+
## Tiling hyperparameters
85+
86+
The following are the parameters you can use to control the tiling feature.
87+
88+
| Parameter Name | Description | Default |
89+
| --------------- |-------------| -------|
90+
| `tile_grid_size` | The grid size to use for tiling each image. Available for use during training, validation, and inference.<br><br>Tuple of two integers passed as a string, e.g `'(3, 2)'`<br><br> *Note: Setting this parameter increases the computation time proportionally, since all tiles and images are processed by the model.*| no default value |
91+
| `tile_overlap_ratio` | Controls the overlap ratio between adjacent tiles in each dimension. When the objects that fall on the tile boundary are too large to fit completely in one of the tiles, increase the value of this parameter so that the objects fit in at least one of the tiles completely.<br> <br> Must be a float in [0, 1).| 0.25 |
92+
| `tile_predictions_nms_thresh` | The intersection over union threshold to use to do non-maximum suppression (nms) while merging predictions from tiles and image. Available during validation and inference. Change this parameter if there are multiple boxes detected per object in the final predictions. <br><br> Must be float in [0, 1]. | 0.25 |
93+
94+
95+
## Example notebooks
96+
97+
See the [object detection sample notebook](https://github.com/Azure/azureml-examples/tree/main/python-sdk/tutorials/automl-with-azureml/image-object-detection/auto-ml-image-object-detection.ipynb) for detailed code examples of setting up and training an object detection model.
98+
99+
>[!NOTE]
100+
> All images in this article are made available in accordance with the permitted use section of the [MIT licensing agreement](https://choosealicense.com/licenses/mit/).
101+
> Copyright © 2020 Roboflow, Inc.
102+
103+
## Next steps
104+
105+
* Learn more about [how and where to deploy a model](/azure/machine-learning/how-to-deploy-managed-online-endpoints).
106+
* For definitions and examples of the performance charts and metrics provided for each job, see [Evaluate automated machine learning experiment results](how-to-understand-automated-ml.md).
107+
* [Tutorial: Train an object detection model (preview) with AutoML and Python](tutorial-auto-train-image-models.md).
108+
* See [what hyperparameters are available for computer vision tasks](reference-automl-images-hyperparameters.md).
109+
*[Make predictions with ONNX on computer vision models from AutoML](how-to-inference-onnx-automl-image-models.md)

0 commit comments

Comments
 (0)