DFC throws exception

I am a beginner and I write a quite simple pytorch net to test the whole process.

class TensorSumModel(nn.Module):
def init(self):
super(TensorSumModel, self).init()

def forward(self, x, y):
    return x + y

Instantiate the model

model = TensorSumModel()
model.eval()

Example dummy inputs (size [1, 3] in this case)

x = torch.randn(1, 3)
y = torch.randn(1, 3)

Export the model to ONNX

torch.onnx.export(
model,
(x, y),
“tensor_sum_model.onnx”,
input_names=[‘x’, ‘y’],
output_names=[‘output’],
opset_version=12
)

after that, I try to convert the onnx to hef file with DFC tool.

onnx_path=“tensor_sum_model.onnx”
har_path=“tensor_sum_model.har”
quantized_har_path=“tensor_sum_quantized_model.har”
hef_path=“tensor_sum_model.hef”

runner=ClientRunner(hw_arch=“hailo8”)
runner.translate_onnx_model(model=onnx_path,start_node_names=[“x”, “y”],end_node_names=[“output”],net_input_shapes={“x”:[1,3],“y”:[1,3]})
runner=ClientRunner(har=har_path)

dataset_x = np.zeros((1, 3)).astype(np.float32)
dataset_y = np.zeros((1, 3)).astype(np.float32)
calibration_data = [{“x”: dataset_x, “y”: dataset_y}]
runner.optimize(calibration_data)
runner.save_har(quantized_har_path)
runner=ClientRunner(har=quantized_har_path)
compiled_hef = runner.compile()
with open(hef_path, “wb”) as f:
f.write(compiled_hef)

it throws “ValueError: Couldn’t detect CalibrationDataType”.
is there anything wrong?

It should be of type .npy if you are testing it this way I believe. I don’t think it directly takes it in the format you are giving it, as just an array/list. You can see code online on how to do generate a numpy array.

If I wrap [{“x”: dataset_x, “y”: dataset_y}] with np.array like np.array([{“x”: dataset_x, “y”: dataset_y}]), it just throws another exception
hailo_model_optimization.acceleras.utils.acceleras_exceptions.BadInputsShape: Data shape () for layer model/input_layer1 doesn’t match network’s input shape (1, 1, 3)

And I cannot find any online sample with two or more input tensors

Hey @sjkof ,

Welcome to the Hailo Community!

Here’s how we can address the ValueError: Couldn't detect CalibrationDataType error:

  1. Check Your Calibration Data Structure
# Correct format example
dataset_x = np.zeros((1, 3), dtype=np.float32)  # Match "x" input shape
dataset_y = np.zeros((1, 3), dtype=np.float32)  # Match "y" input shape
calibration_data = {"x": dataset_x, "y": dataset_y}
runner.optimize([calibration_data])
  1. Verify Your ONNX Model
  • Use Netron to check input/output node names and shapes
  • Update the translation call if needed:
runner.translate_onnx_model(
    model=onnx_path,
    start_node_names=["actual_input_name_1", "actual_input_name_2"],
    end_node_names=["actual_output_name"],
    net_input_shapes={"actual_input_name_1": [1, 3], "actual_input_name_2": [1, 3]}
)
  1. Complete Working Example
import numpy as np
from hailo_platform.runner.client_runner import ClientRunner

# Setup paths
onnx_path = "tensor_sum_model.onnx"
har_path = "tensor_sum_model.har"
quantized_har_path = "tensor_sum_quantized_model.har"
hef_path = "tensor_sum_model.hef"

# Translate ONNX to HAR
runner = ClientRunner(hw_arch="hailo8")
runner.translate_onnx_model(
    model=onnx_path,
    start_node_names=["x", "y"],
    end_node_names=["output"],
    net_input_shapes={"x": [1, 3], "y": [1, 3]}
)
runner.save_har(har_path)

# Optimize with calibration data
runner = ClientRunner(har=har_path)
dataset_x = np.zeros((1, 3), dtype=np.float32)
dataset_y = np.zeros((1, 3), dtype=np.float32)
calibration_data = {"x": dataset_x, "y": dataset_y}
runner.optimize([calibration_data])
runner.save_har(quantized_har_path)

# Compile to HEF
runner = ClientRunner(har=quantized_har_path)
compiled_hef = runner.compile()
with open(hef_path, "wb") as f:
    f.write(compiled_hef)

Let me know if you need any clarification!

I copy your working example and try to run.
I am sure that I keep everything same except “from hailo_platform.runner.client_runner import ClientRunner”, I use “from hailo_sdk_client import ClientRunner” instead.
And unfortunately, it still throws “ValueError: Couldn’t detect CalibrationDataType”