imgly / background-removal-js

Remove backgrounds from images directly in the browser environment with ease and no additional costs or privacy concerns. Explore an interactive demo.
https://img.ly/showcases/cesdk/web/background-removal/web
GNU Affero General Public License v3.0
5.49k stars 339 forks source link

Error: Use builded version @imgly/background-removal-node #49

Closed mrbob64 closed 8 months ago

mrbob64 commented 9 months ago

Hi, I try to use @imgly/background-removal-node (from folder of this repo) in packages/node-examples. I built @imgly/background-removal-node in packages/node. Then I go to packages/node-examples and build&run. I got error: 'Error: Failed to create session: Error: Failed to load model because protobuf parsing failed.. Please check if the publicPath is set correctly.' What's the problem? I didn't change anything

jamesopti commented 8 months ago

@mrbob64 I had a similar error trying to run this in a mono repo. Setting the publicPath worked better:

const publicPath = path.join(
  __dirname,
  '..',
  '..',
  '..',
  'node_modules',
  '@imgly',
  'background-removal-node',
  'dist',
);

const blob = await removeBackground(image_src, {
  publicPath: `file://${publicPath}/`,
})
  .then((blob: Blob) => {
    // The result is a blob encoded as PNG. It can be converted to an URL to be used as HTMLImage.src
    return blob;
  });