Skip to content

C# inference is slower than Python #892

Description

@dashesy

Describe the bug
A clear and concise description of what the bug is.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows for C#, Ubuntu16 for Python
  • ONNX Runtime installed from (source or binary): pip/nuget
  • ONNX Runtime version: 0.3.0
  • Python version: 3.5
  • Visual Studio version (if applicable): 2015

To Reproduce
Load an ONNX file in onnxruntime in Python and in C#, the inference in C# is twice slower

import time
import numpy as np
import onnxruntime as rt

im = np.random.rand(1, 3, 256, 384).astype('uint8')

sess = rt.InferenceSession("model.onnx")

t0 = time.time()
output =  sess.run(['prob'], {'data': im})[0]
print (time.time() - t0)

I get around 0.09s (90ms) but when I load the model in ORT nuget I get about 200ms

using (var results = _session.Run(inputTensor))
{
    return new TensorArray<float>(results.First().AsEnumerable<float>().ToArray(), results.First().AsTensor<float>().Dimensions.ToArray());
}

TensorArray is a wrapper class that accepts float array and its dimension.

Is this behavior expected? is it ToArray that has overhead in C# but not in Python?

Expected behavior
Minimal overhead

Additional context
Sent an email with a model file

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions