Xenova HF staff commited on
Commit
79e7358
1 Parent(s): 109e891

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -5,4 +5,49 @@ pipeline_tag: depth-estimation
5
 
6
  https://huggingface.co/LiheYoung/depth-anything-base-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-base-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-base-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-base-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
+
49
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/5olbEauiVjwNqLd55EyI1.png)
50
+
51
+ ---
52
+
53
  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`).