Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add otx micro benchmark #3762

Merged
merged 48 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e59098e
Add an entry for benchmark
sovrasov Jul 22, 2024
d5bb01e
Draft implementation
sovrasov Jul 24, 2024
aef4b6f
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Jul 24, 2024
f9bd2b9
Update benchmark implementation
sovrasov Jul 24, 2024
e0eecc0
Cover cls models with benchmark
sovrasov Jul 24, 2024
8eda19c
Update becnhamark output
sovrasov Jul 24, 2024
abedae7
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Jul 25, 2024
d6c0e24
Address comments
sovrasov Jul 26, 2024
d21d41d
Enable OV det model benchmark
sovrasov Jul 26, 2024
a2ec9b9
Update torch detection dummy input
sovrasov Jul 26, 2024
043d6f5
Add benchmarking for OV sseg models
sovrasov Jul 26, 2024
e67c8d5
Minor updates in benchmark
sovrasov Jul 26, 2024
9b228e7
Update segmentation and detection support
sovrasov Jul 26, 2024
d5fe882
Add flops counter failure processing
sovrasov Jul 26, 2024
f2b6d60
Cover instance segmentation
sovrasov Jul 26, 2024
6cda33e
Cover anomaly OV model
sovrasov Jul 27, 2024
dd09211
Cover action classification
sovrasov Jul 27, 2024
d4e4929
Cover VPT
sovrasov Jul 27, 2024
cfbb075
Make anomaly model forward runnable (but not functional)
sovrasov Jul 29, 2024
2cfc93f
Fix anomaly forward
sovrasov Jul 29, 2024
e798a67
Simplify OV dummy input
sovrasov Jul 29, 2024
a60e1f5
Add dummy input for VPT
sovrasov Jul 30, 2024
2e84c0f
Add a file output
sovrasov Jul 30, 2024
93f5884
Fix precommit
sovrasov Jul 30, 2024
4053be0
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Jul 30, 2024
501a67e
Update changelog
sovrasov Jul 30, 2024
62e51f3
Del unused var
sovrasov Jul 30, 2024
1262642
Add benchmark tests
sovrasov Jul 30, 2024
64e7326
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Jul 30, 2024
a0b47a3
Update ZSL
sovrasov Jul 30, 2024
0919312
Fix linters
sovrasov Jul 30, 2024
fc1b59f
Add init tests for benchmark
sovrasov Jul 31, 2024
97e522c
Improve unit test coverage
sovrasov Jul 31, 2024
04efb71
Cover VPT
sovrasov Jul 31, 2024
ae27278
Fix typos
sovrasov Jul 31, 2024
0e9175a
Update the engine docstring
sovrasov Jul 31, 2024
61e816d
Fix cls tests
sovrasov Jul 31, 2024
ced91c7
Merge branch 'vs/micro_benchmark' of https://github.com/sovrasov/open…
sovrasov Jul 31, 2024
66467f2
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Jul 31, 2024
c4b83f8
Fix linter
sovrasov Jul 31, 2024
1e06129
Add todo to anomaly task
sovrasov Jul 31, 2024
f74f1b1
Update docs
sovrasov Jul 31, 2024
f4deeb6
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Aug 1, 2024
3ebbad9
Fix missing image size error message
sovrasov Aug 1, 2024
69ed5fd
Fix linters
sovrasov Jul 31, 2024
9a1e800
Revert explicit type conversion
sovrasov Aug 1, 2024
1a56943
Update exporter error message and image size type
sovrasov Aug 1, 2024
fbec481
Merge remote-tracking branch 'origin/develop' into vs/micro_benchmark
sovrasov Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file.
(https://github.com/openvinotoolkit/training_extensions/pull/3749)
- Enable torch.compile to work with classification
(https://github.com/openvinotoolkit/training_extensions/pull/3758)
- Add `otx benchmark` subcommand
(https://github.com/openvinotoolkit/training_extensions/pull/3762)

### Enhancements

Expand Down
40 changes: 34 additions & 6 deletions docs/source/guide/get_started/api_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ If you want to use other models offered by OpenVINO™ Training Extension beside
model_lists = list_models(task="DETECTION", print_table=True)

'''
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ src/otx/recipe/detection/yolox_tiny.yaml │
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ src/otx/recipe/detection/yolox_tiny.yaml │
│ ... │ │ │
└───────────┴───────────────────────┴────────────────────────────────────────────────────────────────┘
'''
Expand Down Expand Up @@ -328,7 +328,7 @@ The datamodule used by the Engine is of type ``otx.core.data.module.OTXDataModul
engine.train(precision="16")

.. note::

This uses lightning's precision value. You can use the values below:
- "64", "32", "16", "bf16",
- 64, 32, 16
Expand Down Expand Up @@ -518,4 +518,32 @@ You can validate the optimized model as the usual model. For example for the NNC

engine.test(checkpoint="<path/to/optimized/ir/xml>")

That's it. Now, we can use OpenVINO™ Training Extensions APIs to create, train, and deploy deep learning models using the OpenVINO™ Training Extension.
************
Benchmarking
************

``Engine`` allows to perform benchmarking of the trained model, and provide theoretical complexity information in case of torch model.
The estimated by ``Engine.benchmark()`` performance may differ from the performance of the deployed model, since the measurements are conducted
via OTX inference API, which can introduce additional burden.

.. tab-set::

.. tab-item:: Benchmark Model

.. code-block:: python

engine.benchmark()

.. tab-item:: Benchmark OpenVINO™ IR model

.. code-block:: python

engine.benchmark(checkpoint="<path/to/exported_model.xml>")

.. note::

Specifying a checkpoint only makes sense for OpenVINO™ IR models.

Conclusion
"""""""""""
That's it! Now, we can use OpenVINO™ Training Extensions APIs to create, train, and deploy deep learning models using the OpenVINO™ Training Extensions.
81 changes: 50 additions & 31 deletions docs/source/guide/get_started/cli_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Help
│ export Export the trained model to OpenVINO Intermediate Representation (IR) or ONNX formats. │
│ optimize Applies NNCF.PTQ to the underlying models (now works only for OV models). │
│ explain Run XAI using the specified model and data (test subset). │
| benchmark Executes model micro benchmarking on random data. |
│ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Expand Down Expand Up @@ -232,43 +233,43 @@ Example to find ready-to-use recipes for the detection task:
.. code-block:: shell

(otx) ...$ otx find --task DETECTION
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ recipe/detection/yolox_tiny.yaml │
│ DETECTION │ atss_mobilenetv2_tile │ recipe/detection/atss_mobilenetv2_tile.yaml │
│ DETECTION │ openvino_model │ recipe/detection/openvino_model.yaml │
│ DETECTION │ atss_mobilenetv2 │ recipe/detection/atss_mobilenetv2.yaml │
│ DETECTION │ atss_resnext101 │ recipe/detection/atss_resnext101.yaml │
│ DETECTION │ yolox_l_tile │ recipe/detection/yolox_l_tile.yaml │
│ DETECTION │ ssd_mobilenetv2_tile │ recipe/detection/ssd_mobilenetv2_tile.yaml │
│ DETECTION │ atss_r50_fpn │ recipe/detection/atss_r50_fpn.yaml │
│ DETECTION │ yolox_tiny_tile │ recipe/detection/yolox_tiny_tile.yaml │
│ DETECTION │ yolox_s │ recipe/detection/yolox_s.yaml │
│ DETECTION │ yolox_s_tile │ recipe/detection/yolox_s_tile.yaml │
│ DETECTION │ rtmdet_tiny │ recipe/detection/rtmdet_tiny.yaml │
│ DETECTION │ yolox_x │ recipe/detection/yolox_x.yaml │
│ DETECTION │ yolox_x_tile │ recipe/detection/yolox_x_tile.yaml │
│ DETECTION │ ssd_mobilenetv2 │ recipe/detection/ssd_mobilenetv2.yaml │
│ DETECTION │ yolox_l │ recipe/detection/yolox_l.yaml │
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ recipe/detection/yolox_tiny.yaml │
│ DETECTION │ atss_mobilenetv2_tile │ recipe/detection/atss_mobilenetv2_tile.yaml │
│ DETECTION │ openvino_model │ recipe/detection/openvino_model.yaml │
│ DETECTION │ atss_mobilenetv2 │ recipe/detection/atss_mobilenetv2.yaml │
│ DETECTION │ atss_resnext101 │ recipe/detection/atss_resnext101.yaml │
│ DETECTION │ yolox_l_tile │ recipe/detection/yolox_l_tile.yaml │
│ DETECTION │ ssd_mobilenetv2_tile │ recipe/detection/ssd_mobilenetv2_tile.yaml │
│ DETECTION │ atss_r50_fpn │ recipe/detection/atss_r50_fpn.yaml │
│ DETECTION │ yolox_tiny_tile │ recipe/detection/yolox_tiny_tile.yaml │
│ DETECTION │ yolox_s │ recipe/detection/yolox_s.yaml │
│ DETECTION │ yolox_s_tile │ recipe/detection/yolox_s_tile.yaml │
│ DETECTION │ rtmdet_tiny │ recipe/detection/rtmdet_tiny.yaml │
│ DETECTION │ yolox_x │ recipe/detection/yolox_x.yaml │
│ DETECTION │ yolox_x_tile │ recipe/detection/yolox_x_tile.yaml │
│ DETECTION │ ssd_mobilenetv2 │ recipe/detection/ssd_mobilenetv2.yaml │
│ DETECTION │ yolox_l │ recipe/detection/yolox_l.yaml │
└───────────┴───────────────────────┴─────────────────────────────────────────────┘

Example to find yolo named model for the detection task:

.. code-block:: shell

(otx) ...$ otx find --task DETECTION --pattern 'yolo*'
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ recipe/detection/yolox_tiny.yaml │
│ DETECTION │ yolox_x │ recipe/detection/yolox_x.yaml │
│ DETECTION │ yolox_l_tile │ recipe/detection/yolox_l_tile.yaml │
│ DETECTION │ yolox_s │ recipe/detection/yolox_s.yaml │
│ DETECTION │ yolox_l │ recipe/detection/yolox_l.yaml │
│ DETECTION │ yolox_x_tile │ recipe/detection/yolox_x_tile.yaml │
│ DETECTION │ yolox_s_tile │ recipe/detection/yolox_s_tile.yaml │
│ DETECTION │ yolox_tiny_tile │ recipe/detection/yolox_tiny_tile.yaml │
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Task ┃ Model Name ┃ Recipe Path ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DETECTION │ yolox_tiny │ recipe/detection/yolox_tiny.yaml │
│ DETECTION │ yolox_x │ recipe/detection/yolox_x.yaml │
│ DETECTION │ yolox_l_tile │ recipe/detection/yolox_l_tile.yaml │
│ DETECTION │ yolox_s │ recipe/detection/yolox_s.yaml │
│ DETECTION │ yolox_l │ recipe/detection/yolox_l.yaml │
│ DETECTION │ yolox_x_tile │ recipe/detection/yolox_x_tile.yaml │
│ DETECTION │ yolox_s_tile │ recipe/detection/yolox_s_tile.yaml │
│ DETECTION │ yolox_tiny_tile │ recipe/detection/yolox_tiny_tile.yaml │
└───────────┴─────────────────┴───────────────────────────────────────┘


Expand Down Expand Up @@ -476,7 +477,7 @@ The command below will generate saliency maps (heatmaps with red colored areas o

.. note::

It is possible to pass both PyTorch weights ``.ckpt`` or OpenVINO™ IR ``exported_model.xml`` to ``--load-weights`` option.
It is possible to pass both PyTorch weights ``.ckpt`` or OpenVINO™ IR ``exported_model.xml`` to ``--checkpoint`` option.

By default, the model is exported to the OpenVINO™ IR format without extra feature information needed for the ``explain`` function. To use OpenVINO™ IR model in ``otx explain``, please first export it with ``--explain`` parameter:

Expand All @@ -486,6 +487,24 @@ By default, the model is exported to the OpenVINO™ IR format without extra fea
--explain True
(otx) ...$ otx explain ... --checkpoint outputs/openvino/with_features \

*******************
Micro-benchmarking
*******************

``otx benchmark`` tool allows performing a fast in-place benchmarking on randomly generated data. The benchmark excludes data loading cost, but takes into account extra burden of OTX API and ModelAPI (in case of OpenVINO™ IR models).

The command requires checkpoint path for OpenVINO™ IR models. In case of torch models, this parameter is optional. Also, for torch model number of trainable parameters and theoretical computational complexity are estimated when model's structure allows that.
It worth noticing that the latency and throughput are depend on batch size. Varying the batch size parameter, one can quickly explore the trade-off for the considered model. For OpenVINO™ IR models batching is imitated by using async inference API.

.. code-block:: shell

(otx) ...$ otx benchmark ... --data_root <path/to/test/root> \
--checkpoint <path/to/model_weights> \
--batch_size 1

.. note::

It is possible to pass both PyTorch weights ``.ckpt`` or OpenVINO™ IR ``exported_model.xml`` to ``--checkpoint`` option.

***********
Workspace
Expand Down
2 changes: 1 addition & 1 deletion src/otx/algo/classification/dino_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _customize_inputs(self, inputs: MulticlassClsBatchDataEntity) -> dict[str, A
"mode": mode,
}
return {
"images": inputs.images,
"images": inputs.stacked_images,
"labels": torch.cat(inputs.labels, dim=0),
"imgs_info": inputs.imgs_info,
"mode": mode,
Expand Down
4 changes: 2 additions & 2 deletions src/otx/algo/classification/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _exporter(self) -> OTXModelExporter:
"""Creates OTXModelExporter object that can export the model."""
return OTXNativeModelExporter(
task_level_export_parameters=self._export_parameters,
input_size=(1, 3, 224, 224),
input_size=self.image_size,
mean=(123.675, 116.28, 103.53),
std=(58.395, 57.12, 57.375),
resize_mode="standard",
Expand Down Expand Up @@ -230,7 +230,7 @@ def _customize_inputs(self, inputs: MulticlassClsBatchDataEntity) -> dict[str, A
"mode": mode,
}
return {
"images": inputs.images,
"images": inputs.stacked_images,
"labels": torch.cat(inputs.labels, dim=0),
"imgs_info": inputs.imgs_info,
"mode": mode,
Expand Down
4 changes: 2 additions & 2 deletions src/otx/algo/classification/efficientnet_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _exporter(self) -> OTXModelExporter:
"""Creates OTXModelExporter object that can export the model."""
return OTXNativeModelExporter(
task_level_export_parameters=self._export_parameters,
input_size=(1, 3, 224, 224),
input_size=self.image_size,
mean=(123.675, 116.28, 103.53),
std=(58.395, 57.12, 57.375),
resize_mode="standard",
Expand Down Expand Up @@ -222,7 +222,7 @@ def _customize_inputs(self, inputs: MulticlassClsBatchDataEntity) -> dict[str, A
"mode": mode,
}
return {
"images": inputs.images,
"images": inputs.stacked_images,
"labels": torch.cat(inputs.labels, dim=0),
"imgs_info": inputs.imgs_info,
"mode": mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ def predict(

def _get_predictions(self, cls_score: torch.Tensor) -> torch.Tensor:
"""Get the score from the classification score."""
return functional.softmax(cls_score, dim=1)
return functional.softmax(cls_score, dim=-1)
eunwoosh marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/otx/algo/classification/huggingface_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _exporter(self) -> OTXModelExporter:
"""Creates OTXModelExporter object that can export the model."""
return OTXNativeModelExporter(
task_level_export_parameters=self._export_parameters,
input_size=(1, 3, 224, 224),
input_size=self.image_size,
mean=(123.675, 116.28, 103.53),
std=(58.395, 57.12, 57.375),
resize_mode="standard",
Expand Down
4 changes: 2 additions & 2 deletions src/otx/algo/classification/mobilenet_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _exporter(self) -> OTXModelExporter:
"""Creates OTXModelExporter object that can export the model."""
return OTXNativeModelExporter(
task_level_export_parameters=self._export_parameters,
input_size=(1, 3, 224, 224),
input_size=self.image_size,
mean=(123.675, 116.28, 103.53),
std=(58.395, 57.12, 57.375),
resize_mode="standard",
Expand Down Expand Up @@ -237,7 +237,7 @@ def _customize_inputs(self, inputs: MulticlassClsBatchDataEntity) -> dict[str, A
"mode": mode,
}
return {
"images": inputs.images,
"images": inputs.stacked_images,
"labels": torch.cat(inputs.labels, dim=0),
"imgs_info": inputs.imgs_info,
"mode": mode,
Expand Down
Loading
Loading