Error when run demo code on Chrome

#1
by tidus2102 - opened

hi, I try to run demo code but got error at this line:

const { output_image } = await model({ input_image: pixel_values });

Screenshot 2024-08-25 at 22.19.31.jpg

main.js:

import { AutoModel, AutoProcessor, RawImage } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers';

// Load model and processor
const model_id = 'onnx-community/BiRefNet_T';
const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
const processor = await AutoProcessor.from_pretrained(model_id);

// Load image from URL
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const image = await RawImage.fromURL(url);

// Pre-process image
const { pixel_values } = await processor(image);

// Predict alpha matte
const { output_image } = await model({ input_image: pixel_values });

// Save output mask
const mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);
mask.save('mask.png');

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Background Removal</title>
</head>
<body>
<script type="module" src="/main.js"></script>
</body>
</html>

Please help to check it. Thank you.

Hi @Xenova , please help to check this issue. Thank you.

I am getting An error occurred during model execution: "246040216". with 3.0.0-alpha.14

ONNX Community org

Hi there! We've only tested with Node.js. The error you're facing seems to be an out-of-memory issue (which may make sense since the images are processed at the full resolution of 1024x1024). cc @schmuell might be able to help.

tidus2102 changed discussion title from Error when run demo code to Error when run demo code on Chrome
ONNX Community org

filed a webgpu issue for this:
https://github.com/microsoft/onnxruntime/issues/21968
Yes, using lots of memory but should still work.
Somebody is looking into it.

Sign up or log in to comment