Description
In practice I'm encountering models with different types on different outputs. As an example of the problem, a trivial TensorFlow model that takes string input and returns the unique elements of the input tensor produces this ONNX structure:
Inputs:
0:
name = input_1:0
type = String
dimensions = [None]
Outputs:
0:
name = Identity:0
type = Int32
dimensions = [None]
1:
name = Identity_1:0
type = String
dimensions = [None]
The two outputs are of different types, so the current type structure for retrieving output that assumes one type for all outputs won't work.
One way to go about it would be to add a trait like the equivalent on the input side:
pub trait `: Sized {
/// The tensor element type that this type can extract from
fn tensor_element_data_type() -> TensorElementDataType;
/// Extract an `ArrayView` from the ort-owned tensor.
fn extract_array<'a, D: ndarray::Dimension>(
shape: D,
tensor: *mut sys::OrtValue,
) -> Result<ndarray::ArrayView<'a, Self, D>>;
}
We could provide implementations of that trait for all the common types that map to ONNX types, as on the input side. In the String case the data would have to be copied, as far as I can tell. Output could be in the form of some new dynamic tensor type that exposes, for each output, the TensorElementDataType
so that the user can then use an appropriate type with an OwnedTensorDataToType
that matches.