-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
I'm trying to use transform.js with MetaAI SAM, it cost above half a min to segment a 540p picture.
How to reproduce
Steps or a minimal working example to reproduce the behavior
Expected behavior
A clear and concise description of what you expected to happen.
Maybe faster?
Environment
- Transformers.js version: 1.4.2
- Browser (if applicable): Edge 112.0.1722.34
- Operating system (if applicable): MacOS 13.2.1
- Other:
Additional context
Add any other context about the problem here.
get warning from console:
-nodewas not found. Usingonnxruntime-webas a fallback. We recommend installingonnxruntime-node` as it generally improves performance (up to 5X).
Source Code
import { pipeline } from '@xenova/transformers';
(async function main() {
performance.mark('segmentation');
let segmenter = await pipeline('image-segmentation', 'facebook/detr-resnet-50-panoptic');
let img = 'img'
let outputs = await segmenter('https://cdn.pixabay.com/photo/2017/02/20/18/03/cat-2083492__340.jpg');
performance.mark('segmentation-end');
console.log(performance.measure('segmentation-elapse', 'segmentation', 'segmentation-end'));
console.log(outputs);
const cat = outputs.find(out => out.label === 'cat');
const image = new ImageData(cat.mask.width, cat.mask.height);
const canvas = document.createElement('canvas');
canvas.width = cat.mask.width;
canvas.height = cat.mask.height;
const ctx = canvas.getContext('2d');
cat.mask.data.forEach((d, index) => {
const offset = index * 4
if (d === 255) {
image.data.set([255, 99, 71, 255], offset)
} else {
}
})
ctx.putImageData(image, 0, 0);
document.documentElement.append(canvas);
})()
