Skip to content

[core] Cast operation not working

Applying a node Cast with targetType uint8 on a float tensor is not working.
Here is the test script:

import aidge_core; import aidge_backend_cpu; import aidge_onnx
import numpy as np

cast_node = aidge_core.Cast(aidge_core.dtype.uint8, "cast_node")
cast_graph = aidge_core.get_connected_graph_view(cast_node)

X = np.random.rand(1, 3, 3).astype(np.float32) * 255  # Scale to match UINT8 range
x_tensor = aidge_core.Tensor(X)

cast_graph.compile("cpu", aidge_core.dtype.float32, dims=[[1, 3, 3]])
scheduler = aidge_core.SequentialScheduler(cast_graph)

scheduler.forward(data=[x_tensor])
for outNode in cast_graph.get_output_nodes():
	output_aidge = np.array(outNode.get_operator().get_output(0))
	print("Aidge output: \n",output_aidge)

The output is still float.

Edited by Houssem ROUIS