Xenova HF staff commited on
Commit
358f2f2
1 Parent(s): 41cefae

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +0 -75
README.md CHANGED
@@ -4,79 +4,4 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/nielsr/slimsam-77-uniform with ONNX weights to be compatible with Transformers.js.
6
 
7
- ## Usage (Transformers.js)
8
-
9
- 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:
10
- ```bash
11
- npm i @xenova/transformers
12
- ```
13
-
14
- **Example:** Perform mask generation with `Xenova/slimsam-77-uniform`.
15
-
16
- ```js
17
- import { SamModel, AutoProcessor, RawImage } from '@xenova/transformers';
18
-
19
- // Load model and processor
20
- const model = await SamModel.from_pretrained('Xenova/slimsam-77-uniform');
21
- const processor = await AutoProcessor.from_pretrained('Xenova/slimsam-77-uniform');
22
-
23
- // Prepare image and input points
24
- const img_url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg';
25
- const raw_image = await RawImage.read(img_url);
26
- const input_points = [[[340, 250]]] // 2D localization of a window
27
-
28
- // Process inputs and perform mask generation
29
- const inputs = await processor(raw_image, input_points);
30
- const outputs = await model(inputs);
31
-
32
- // Post-process masks
33
- const masks = await processor.post_process_masks(outputs.pred_masks, inputs.original_sizes, inputs.reshaped_input_sizes);
34
- console.log(masks);
35
- // [
36
- // Tensor {
37
- // dims: [ 1, 3, 410, 614 ],
38
- // type: 'bool',
39
- // data: Uint8Array(755220) [ ... ],
40
- // size: 755220
41
- // }
42
- // ]
43
- const scores = outputs.iou_scores;
44
- console.log(scores);
45
- // Tensor {
46
- // dims: [ 1, 1, 3 ],
47
- // type: 'float32',
48
- // data: Float32Array(3) [
49
- // 0.8350210189819336,
50
- // 0.9786665439605713,
51
- // 0.8379436731338501
52
- // ],
53
- // size: 3
54
- // }
55
- ```
56
-
57
- You can then visualize the generated mask with:
58
-
59
- ```js
60
- const image = RawImage.fromTensor(masks[0][0].mul(255));
61
- image.save('mask.png');
62
- ```
63
-
64
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/2vWMNptPh5jJKdLrnUIik.png)
65
-
66
- Next, select the channel with the highest IoU score, which in this case is the second (green) channel. Intersecting this with the original image gives us an isolated version of the subject:
67
-
68
- ![image/gif](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/ATwz4cQEZyUwU2BsOTq92.gif)
69
-
70
-
71
-
72
- ## Demo
73
-
74
- We've also got an online demo, which you can try out [here](https://huggingface.co/spaces/Xenova/segment-anything-web).
75
-
76
-
77
- <video controls autoplay src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/Y0wAOw6hz9rWpwiuMoz2A.mp4"></video>
78
-
79
- ---
80
-
81
-
82
  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`).
 
4
 
5
  https://huggingface.co/nielsr/slimsam-77-uniform with ONNX weights to be compatible with Transformers.js.
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  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`).