microsoft / microsoft/onnxruntime-inference-examples

Error: Can't access output tensor data. error code = 1

Open
#282 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.7k
Forks
414
Avg merge
1d 6h
Merged PRs (30d)
14

Description

PRIORITY: URGENT

Hi, I am using onnx runtime in a web browser. Following are the steps and set up I follow

  1. Trained random forest classifier using sklearn package in python
  2. Converting the model in .onnx format using the following code. Here X_train.toarray()[0] is the length of the feature for a given data point
initial_type = [('float_input', FloatTensorType(
        [None, len(X_train.toarray()[0])]))]
onx = convert_sklearn(random_forest, initial_types=initial_type,
                          target_opset=12)

with open(model_file_name, "wb") as f:
        f.write(onx.SerializeToString())
  1. Now I want to predict some data in the browser using HTML. Here is my file
<!DOCTYPE html>
<html>

<head>
	<title>SOT_POC</title>
</head>

<body>
	<!-- import ONNXRuntime Web from CDN -->
	<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js"></script>

	<script>
		fetch('./data/2023-08-01/python/10_default_tokenizer_test_data_RF/qoh1_test_data.json')
			.then((response) => response.json())
			.then(async (data) => {
				const session = await ort.InferenceSession.create(
					'./data/2023-08-01/js/10_default_tokenizer_models_RF/qoh1_model.onnx',
				);

				let inputDataFloat32 = data['test_transformed_data'].reduce((acc, val) => acc.concat(val), []);
				inputDataFloat32 = Float32Array.from(inputDataFloat32);

				const tensor = new ort.Tensor('float32', inputDataFloat32, [data['test_transformed_data'].length, data['test_transformed_data'][0].length]);
				
				const results = await session.run({ float_input: tensor });
				// console.log(results);
			})
			.catch((error) => {
				console.error('Error loading JSON file:', error);
			});
      // });
	</script>
</body>

</html>

But when I run the file I am getting the following error
Can't access output tensor data. error code = 1.

When you try to console log the tensor it gives the correct value. here is the truncated value
Object { dims: (2) […], type: "float32", data: Float32Array(2232), size: 2232 }

I have a total of 31 test points and each data point has 72 feature points. That's why the total length is 31*72=2232.

I checked every possible solution, did not work any of them. Please share your views

PRIORITY: URGENT

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the inline HTML browser example, especially the ort.InferenceSession.create and session.run calls, and inspect the referenced JSON and ONNX model paths. Reproduce the failure with the 31-by-72 input and compare the logged tensor with the result returned by session.run; done means the output can be accessed without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
machine-learning, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.