|
| 1 | +# /usr/bin/env python3 |
| 2 | +# -*- mode: python -*- |
| 3 | +# ============================================================================= |
| 4 | +# @@-COPYRIGHT-START-@@ |
| 5 | +# |
| 6 | +# Copyright (c) 2023 of Qualcomm Innovation Center, Inc. All rights reserved. |
| 7 | +# Changes from QuIC are licensed under the terms and conditions at |
| 8 | +# https://github.com/quic/aimet-model-zoo/blob/develop/LICENSE.pdf |
| 9 | +# |
| 10 | +# @@-COPYRIGHT-END-@@ |
| 11 | +# ============================================================================= |
| 12 | +""" acceptance test for ffnet semantic segmentation""" |
| 13 | +import pytest |
| 14 | +from math import isclose |
| 15 | + |
| 16 | +import torch |
| 17 | + |
| 18 | +from aimet_zoo_torch.ffnet.evaluators import ( |
| 19 | + ffnet_quanteval, |
| 20 | +) |
| 21 | + |
| 22 | +expected_results = { |
| 23 | + 'segmentation_ffnet40S_dBBB_mobile': {'original_mIoU': 0.7015, 'quantized_mIoU': 0.7018}, |
| 24 | + 'segmentation_ffnet54S_dBBB_mobile': {'original_mIoU': 0.6957, 'quantized_mIoU': 0.7368}, |
| 25 | + 'segmentation_ffnet78S_BCC_mobile_pre_down': {'original_mIoU': None, 'quantized_mIoU': None}, |
| 26 | + 'segmentation_ffnet78S_dBBB_mobile': {'original_mIoU': 0.6904, 'quantized_mIoU': 0.6882}, |
| 27 | + 'segmentation_ffnet122NS_CCC_mobile_pre_down': {'original_mIoU': None, 'quantized_mIoU': None} |
| 28 | +} |
| 29 | + |
| 30 | +@pytest.mark.sementic_segmentation |
| 31 | +@pytest.mark.cuda |
| 32 | +#pylint:disable = redefined-outer-name |
| 33 | +@pytest.mark.parametrize( |
| 34 | + "model_config, expected_mIoUs",[ |
| 35 | + ("segmentation_ffnet40S_dBBB_mobile", expected_results["segmentation_ffnet40S_dBBB_mobile"]), |
| 36 | + ("segmentation_ffnet54S_dBBB_mobile", expected_results["segmentation_ffnet54S_dBBB_mobile"]), |
| 37 | + ("segmentation_ffnet78S_BCC_mobile_pre_down", expected_results["segmentation_ffnet78S_BCC_mobile_pre_down"]), |
| 38 | + ("segmentation_ffnet78S_dBBB_mobile", expected_results["segmentation_ffnet78S_dBBB_mobile"]), |
| 39 | + ("segmentation_ffnet122NS_CCC_mobile_pre_down", expected_results["segmentation_ffnet122NS_CCC_mobile_pre_down"]) |
| 40 | + ] |
| 41 | + ) |
| 42 | +def test_quaneval_ffnet( |
| 43 | + model_config, |
| 44 | + expected_mIoUs, |
| 45 | + tiny_cityscapes_path |
| 46 | +): |
| 47 | + """acceptance test of hrnet for semantic segmentation""" |
| 48 | + torch.cuda.empty_cache() |
| 49 | + if tiny_cityscapes_path is None: |
| 50 | + pytest.xfail('Dataset is not set') |
| 51 | + |
| 52 | + #TODO: Fix the two failing model cards |
| 53 | + if expected_mIoUs['original_mIoU'] is None: |
| 54 | + pytest.skip(f'{model_config} hasn`t passed manual testing!') |
| 55 | + |
| 56 | + mIoUs = ffnet_quanteval.main( |
| 57 | + [ |
| 58 | + "--model-config", model_config, |
| 59 | + "--dataset-path", tiny_cityscapes_path, |
| 60 | + "--batch-size", '2' |
| 61 | + ] |
| 62 | + ) |
| 63 | + |
| 64 | + assert isclose(mIoUs['mIoU_orig_fp32'], expected_mIoUs['original_mIoU'], rel_tol=1e-4) |
| 65 | + assert isclose(mIoUs['mIoU_optim_int8'], expected_mIoUs['quantized_mIoU'], rel_tol=1e-4) |
0 commit comments