-
Notifications
You must be signed in to change notification settings - Fork 778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Depth Anything #534
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Very nice, I wanted to test it directly in the browser and came up with this: const depth_estimator = await pipeline('depth-estimation', 'Xenova/depth-anything-small-hf');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png';
const output = await depth_estimator(url);
function rawImageToCanvas({width, height, data}) {
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const imageData = new ImageData(width, height);
const {length} = data;
let j = 0;
for (let i = 0; i < length; i++) {
const color = data[i];
imageData.data[j++] = color;
imageData.data[j++] = color;
imageData.data[j++] = color;
imageData.data[j++] = 255; // make sure it's opaque
}
canvas.getContext('2d').putImageData(imageData, 0, 0);
return canvas;
}
const canvas = rawImageToCanvas(output.depth);
document.body.prepend(canvas); // add to top for quick testing without scrolling Output: (first I tried |
I believe that's because it's an OffscreenCanvas element, and you will need to create a normal Canvas from it. |
Good point, just tested it and it works: const {depth} = output;
const canvas = document.createElement('canvas');
canvas.width = depth.width;
canvas.height = depth.height;
const offscreenCanvas = output.depth.toCanvas();
const imageData = offscreenCanvas.getContext("2d").getImageData(0, 0, depth.width, depth.width);
canvas.getContext('2d').putImageData(imageData, 0, 0);
document.body.prepend(canvas); |
Possible now that huggingface/transformers#28654 is merged.
Example: Depth estimation with
Xenova/depth-anything-small-hf
.You can visualize the output with:
cc @NielsRogge