Skip to content

[Error: Exception in HostFunction: <unknown>] while running ort models in react-native #19021

Open
@eumentis-madhurzanwar

Description

@eumentis-madhurzanwar

Describe the issue

I am trying to run a ort model in react-native using onnxruntime-react-native. I load the model and create an Inference Session.

Screenshot 2024-01-05 144134

I follow the steps given in the docs. But when I run Session.run I get error [Error: Exception in HostFunction: ]

To reproduce

// loading image from path
  const image = await ImageUtil.fromFile(path);
  console.log('The fly image was successfully loaded:', path);

  let imageWidth = image.getWidth();
  let imageHeight = image.getHeight();

  // Convert image to blob, which is a byte representation of the image
  // in the format height (H), width (W), and channels (C), or HWC for short
  const blob = media.toBlob(image);

  // Get a tensor from image the blob and also define in what format
  // the image blob is.
  let tensor = torch.fromBlob(blob, [imageHeight, imageWidth, 3]);

  // Rearrange the tensor shape to be [CHW]
  tensor = tensor.permute([2, 0, 1]);

  // Divide the tensor values by 255 to get values between [0, 1]
  // tensor = tensor.div(255);

  const resize = T.resize([640, 640]);
  tensor = resize(tensor);

  const formattedInputTensor = tensor.unsqueeze(0);

  let session;

  // Load model if not loaded
  if (model == null) {
    console.log('Loading model...');
    session = await InferenceSession.create(modelFilePath);
    console.log('session successfully loaded');
  }

  const inputs = session.inputNames;
  const outputs = session.outputNames;

  const feeds = {
    normalized_input_image_tensor: formattedInputTensor,
 
  };

  session
    .run(feeds, outputs)
    .then(result => {
      console.log(result);
    })
    .catch(err => {
      console.log('err', err);
    });

Session.run throws the error [Error: Exception in HostFunction: ]

Urgency

No response

Platform

Android

OS Version

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

onnxruntime-react-native

ONNX Runtime Version or Commit ID

1.16.3

ONNX Runtime API

JavaScript

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:Javascriptissues related to the Javascript APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions