How can I optimize the model which have multi-input?

Hi, when optimize the model which have four input, it failed with the message below.

(hailo_virtualenv) hailo@ts:/local/shared_with_docker/pc$ python optimize.py
[info] Starting Model Optimization
Process Process-2:
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/acceleras/utils/tf_utils.py", line 99, in child_proc
    dataset, _ = data_to_dataset(data, data_type)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/acceleras/utils/dataset_util.py", line 258, in data_to_dataset
    raise ValueError("Couldn't detect CalibrationDataType")
ValueError: Couldn't detect CalibrationDataType
Traceback (most recent call last):
  File "/local/shared_with_docker/pc/optimize.py", line 14, in <module>
    runner.optimize(calib_dataset)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
    return func(self, *args, **kwargs)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 2201, in optimize
    result = self._optimize(
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
    return func(self, *args, **kwargs)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 2020, in _optimize
    checkpoint_info = self._sdk_backend.full_quantization(
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1196, in full_quantization
    new_checkpoint_info = self._full_acceleras_run(
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1415, in _full_acceleras_run
    mo_config = parser.run()
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/tools/mo_script_parser.py", line 86, in run
    default_cfg = self._parse_flavor_to_default_cfg(flavors_commands)
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/tools/mo_script_parser.py", line 113, in _parse_flavor_to_default_cfg
    data_length = get_tf_dataset_length(
  File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/acceleras/utils/tf_utils.py", line 109, in get_tf_dataset_length
    raise SubprocessFailure(f"Dataset length check subprocess failed with exitcode {proc.exitcode}")
hailo_model_optimization.acceleras.utils.acceleras_exceptions.SubprocessFailure: Dataset length check subprocess failed with exitcode 1

My optimize code is here:

from hailo_sdk_client import ClientRunner
import numpy as np

data_shape = (1024,144,2)
calib_dataset = [np.random.randn(1024,144,2), np.random.randn(1024,144,2), np.random.randn(1024,144,2), np.random.randn(1024,144,2)]
for i in range(4):
    calib_dataset[i] = calib_dataset[i].astype(np.float32)
hailo_model_har_name = 'model/div.har'
runner = ClientRunner(har=hailo_model_har_name)
runner.optimize(calib_dataset)
quantized_model_har_path = f'model/div_quantized_model.har'
runner.save_har(quantized_model_har_path)

Please help me to optimize the model with multi-input, Thanks.

input_layer_names = [k for k, v in runner.get_hn()['layers'].items()
                     if v['type'] == 'input_layer']

calib_dataset = {name: np.random.randn(1024, 144, 2) for name in input_layer_names}

runner.optimize(calib_datset)

For multiple inputs, you supply a dict where the key is the input layer’s name and the value is the numpy array.

2 Likes

@lawrence Hi, thanks for your response. Following your advice, I resolved the issue.

2 Likes