Skip to content

Conversation

@xenova
Copy link
Collaborator

@xenova xenova commented Mar 24, 2025

Closes #1247

Example usage w/ pipeline API:

import { pipeline } from '@huggingface/transformers';

const model = 'onnx-community/metric3d-vit-small';
const depth_estimator = await pipeline('depth-estimation', model);

// Predict depth of an image
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg';
const { depth, predicted_depth } = await depth_estimator(url);

// Visualize the output
depth.save('depth.png');

// Or access the raw values with `predicted_depth`
console.log(predicted_depth);
// Tensor {
//   data: Float32Array(307200) [
//     1.9032787084579468, 1.8878453969955444, 1.8748314380645752,
//     ...
//   ],
//   type: 'float32',
//   dims: [ 480, 640 ],
//   size: 307200
// }

image

Example usage w/ AutoModel API:

import { AutoProcessor, AutoModelForDepthEstimation, RawImage } from '@huggingface/transformers';

const model_id = 'onnx-community/metric3d-vit-small';
const model = await AutoModelForDepthEstimation.from_pretrained(model_id);
const processor = await AutoProcessor.from_pretrained(model_id);

const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg';
const image = await RawImage.fromURL(url);
const inputs = await processor(image);
const { predicted_depth, predicted_normal, normal_confidence } = await model(inputs);

console.log(predicted_depth);
console.log(predicted_normal);
console.log(normal_confidence);

@HuggingFaceDocBuilderDev

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.

@xenova xenova merged commit 566ef11 into main Mar 25, 2025
4 checks passed
@xenova xenova deleted the add-metric3d branch March 25, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

metric3d Model unsupported for Depth Animation

3 participants