Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,48 @@ pipeline_tag: depth-estimation
|
|
5 |
|
6 |
https://huggingface.co/LiheYoung/depth-anything-large-hf with ONNX weights to be compatible with Transformers.js.
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|
|
|
5 |
|
6 |
https://huggingface.co/LiheYoung/depth-anything-large-hf with ONNX weights to be compatible with Transformers.js.
|
7 |
|
8 |
+
## Usage (Transformers.js)
|
9 |
+
|
10 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
|
11 |
+
```bash
|
12 |
+
npm i @xenova/transformers
|
13 |
+
```
|
14 |
+
|
15 |
+
**Example:** Depth estimation with `Xenova/depth-anything-large-hf`.
|
16 |
+
|
17 |
+
```js
|
18 |
+
import { pipeline } from '@xenova/transformers';
|
19 |
+
|
20 |
+
// Create depth-estimation pipeline
|
21 |
+
const depth_estimator = await pipeline('depth-estimation', 'Xenova/depth-anything-large-hf');
|
22 |
+
|
23 |
+
// Predict depth map for the given image
|
24 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png';
|
25 |
+
const output = await depth_estimator(url);
|
26 |
+
// {
|
27 |
+
// predicted_depth: Tensor {
|
28 |
+
// dims: [350, 518],
|
29 |
+
// type: 'float32',
|
30 |
+
// data: Float32Array(181300) [...],
|
31 |
+
// size: 181300
|
32 |
+
// },
|
33 |
+
// depth: RawImage {
|
34 |
+
// data: Uint8Array(271360) [...],
|
35 |
+
// width: 640,
|
36 |
+
// height: 424,
|
37 |
+
// channels: 1
|
38 |
+
// }
|
39 |
+
// }
|
40 |
+
```
|
41 |
+
|
42 |
+
You can visualize the output with:
|
43 |
+
|
44 |
+
```js
|
45 |
+
output.depth.save('depth.png');
|
46 |
+
```
|
47 |
+
|
48 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/eOvfmNS46yW5gaULNF5_G.png)
|
49 |
+
|
50 |
+
---
|
51 |
+
|
52 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|