Skip to content

Commit 18ab25c

Browse files
Update nncf export (open-edge-platform#2286)
* update nncf export Signed-off-by: Ashwin Vaidya <[email protected]> * update accuracy aware training Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 9e58ab3 commit 18ab25c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/anomalib/engine/engine.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -912,22 +912,22 @@ def export(
912912
CLI Usage:
913913
1. To export as a torch ``.pt`` file you can run the following command.
914914
```python
915-
anomalib export --model Padim --export_mode torch --ckpt_path <PATH_TO_CHECKPOINT>
915+
anomalib export --model Padim --export_type torch --ckpt_path <PATH_TO_CHECKPOINT>
916916
```
917917
2. To export as an ONNX ``.onnx`` file you can run the following command.
918918
```python
919-
anomalib export --model Padim --export_mode onnx --ckpt_path <PATH_TO_CHECKPOINT> \
919+
anomalib export --model Padim --export_type onnx --ckpt_path <PATH_TO_CHECKPOINT> \
920920
--input_size "[256,256]"
921921
```
922922
3. To export as an OpenVINO ``.xml`` and ``.bin`` file you can run the following command.
923923
```python
924-
anomalib export --model Padim --export_mode openvino --ckpt_path <PATH_TO_CHECKPOINT> \
925-
--input_size "[256,256] --compression_type "fp16"
924+
anomalib export --model Padim --export_type openvino --ckpt_path <PATH_TO_CHECKPOINT> \
925+
--input_size "[256,256] --compression_type FP16
926926
```
927927
4. You can also quantize OpenVINO model with the following.
928928
```python
929-
anomalib export --model Padim --export_mode openvino --ckpt_path <PATH_TO_CHECKPOINT> \
930-
--input_size "[256,256]" --compression_type "int8_ptq" --data MVTec
929+
anomalib export --model Padim --export_type openvino --ckpt_path <PATH_TO_CHECKPOINT> \
930+
--input_size "[256,256]" --compression_type INT8_PTQ --data MVTec
931931
```
932932
"""
933933
export_type = ExportType(export_type)

src/anomalib/models/components/base/export_mixin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,14 @@ def _post_training_quantization_ov(
330330
if datamodule is None:
331331
msg = "Datamodule must be provided for OpenVINO INT8_PTQ compression"
332332
raise ValueError(msg)
333+
datamodule.setup("fit")
333334

334335
model_input = model.input(0)
335336

336337
if model_input.partial_shape[0].is_static:
337338
datamodule.train_batch_size = model_input.shape[0]
338339

339-
dataloader = datamodule.train_dataloader()
340+
dataloader = datamodule.val_dataloader()
340341
if len(dataloader.dataset) < 300:
341342
logger.warning(
342343
f">300 images recommended for INT8 quantization, found only {len(dataloader.dataset)} images",
@@ -373,6 +374,8 @@ def _accuracy_control_quantization_ov(
373374
if datamodule is None:
374375
msg = "Datamodule must be provided for OpenVINO INT8_PTQ compression"
375376
raise ValueError(msg)
377+
datamodule.setup("fit")
378+
376379
if metric is None:
377380
msg = "Metric must be provided for OpenVINO INT8_ACQ compression"
378381
raise ValueError(msg)
@@ -383,14 +386,14 @@ def _accuracy_control_quantization_ov(
383386
datamodule.train_batch_size = model_input.shape[0]
384387
datamodule.eval_batch_size = model_input.shape[0]
385388

386-
dataloader = datamodule.train_dataloader()
389+
dataloader = datamodule.val_dataloader()
387390
if len(dataloader.dataset) < 300:
388391
logger.warning(
389392
f">300 images recommended for INT8 quantization, found only {len(dataloader.dataset)} images",
390393
)
391394

392395
calibration_dataset = nncf.Dataset(dataloader, lambda x: x["image"])
393-
validation_dataset = nncf.Dataset(datamodule.val_dataloader())
396+
validation_dataset = nncf.Dataset(datamodule.test_dataloader())
394397

395398
if isinstance(metric, str):
396399
metric = create_metric_collection([metric])[metric]

0 commit comments

Comments
 (0)