dotnet / dotnet/machinelearning

Add OnnxTransform test for variable length vectors

Open
#3,375 0 comments 0 reactions 0 assignees View on GitHub
area-ONNX Priority:2 test-enhancement
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

## Issue
We need a test for OnnxTransform that uses variable length vectors as input.

## Details
The OnnxTransform does not allow for input that is of variable length vector type, however variable length vectors are supported in ONNX. This check could be removed if we have tests that use a model that has a variable length vector.

I initially tried via sci-kit learn to create an onnx model using the CountVectorizer which would result in variable length vectors, however loading this model in ml.net failed due to missing string support.

Next attempt is to create a simple ONNX model using argmax and have it take multiple inputs, script is here for reference:

```
import onnx
from onnx import helper
from onnx import AttributeProto, TensorProto, GraphProto

height=1
width=1
isize = height * width

input = helper.make_tensor_value_info('input', TensorProto.FLOAT , [-1, -1])
argmax = helper.make_tensor_value_info('argmax', TensorProto.INT64, [-1])
nodea = helper.make_node(
    'ArgMax',  # node name
    ['input'],  # inputs
    ['argmax'],  # outputs
    axis = 1,
    keepdims = 0
)

# Create the graph (GraphProto)
graph_def = helper.make_graph(
    [nodea],
    'argmax',
    [input],
    [argmax]
)

# Create the model (ModelProto)
model_def = helper.make_model(graph_def, producer_name='AIInfra')
#
#print('The model is:\n{}'.format(model_def))
onnx.save(model_def, 'test_unknowndimensions_float.onnx')
```

If this does work, we will need to add the ONNX model to https://github.com/dotnet/machinelearning-testdata

As this generates the nuget file that contains our onnx test models.

CC @jignparm

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.