microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.1k stars 2.84k forks source link

[Web] Cannot Convert to RGB when using Tensor.fromImage(image,{tensorFormat:'RGB'}) #17094

Open gidich opened 1 year ago

gidich commented 1 year ago

Describe the issue

The functionality of Tensor.fromImage does not allow the tensorFormat option to function as expected due to a bug in the code.

https://github.com/microsoft/onnxruntime/blob/ef6f4a4aa1dbf9278379e630055a3075e5cda60e/js/common/lib/tensor-factory-impl.ts#L133C1-L137C10

Notice the if statement is referencing options.tensorFormat, when it should be referencing options.inputFormat

To reproduce

When loading from image:

import { Tensor,TensorFactory, InferenceSession } from "onnxruntime-web";

((Tensor as any) as TensorFactory).fromImage(image, {tensorFormat:'RGB'}).then((tensor)=>{
    console.log('tensor',newTensor);
}).catch((err)=>{
    console.log('err',err);
});

Results in the following error:

Error: Image input config format must be RGBA for HTMLImageElement

Urgency

Without this, the library always loads tensors as RGBA when using fromImage. It will require the manual formatting of the image to create the tensor manually without the aid of the library.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.15.1

Execution Provider

'wasm'/'cpu' (WebAssembly CPU)

sebastian-east commented 1 year ago

I've also encountered this issue.

gidich commented 3 months ago

Bump! - Any updates on this?

virgil724 commented 1 month ago

https://github.com/microsoft/onnxruntime/blob/94eb70d98348d83343207e113f9abaa0e7c6ea37/js/common/lib/tensor-factory-impl.ts#L149-L150

It looks like there's no implementation of any RGB conversion.