Update copyright headers
This commit is contained in:
parent
d398eb176f
commit
e72b94dbed
@ -1,11 +1,19 @@
|
|||||||
## Segment Anything Simple Web demo
|
## Segment Anything Simple Web demo
|
||||||
|
|
||||||
This **front-end only** demo shows how to load a fixed image and `.npy` file of the SAM image embedding, and run the SAM ONNX model in the browser using Web Assembly with mulithreading enabled by `SharedArrayBuffer`, Web Worker, and SIMD128.
|
This **front-end only** React based web demo shows how to load a fixed image and corresponding `.npy` file of the SAM image embedding, and run the SAM ONNX model in the browser using Web Assembly with mulithreading enabled by `SharedArrayBuffer`, Web Worker, and SIMD128.
|
||||||
|
|
||||||
<img src="https://github.com/facebookresearch/segment-anything/raw/main/assets/minidemo.gif" width="500"/>
|
<img src="https://github.com/facebookresearch/segment-anything/raw/main/assets/minidemo.gif" width="500"/>
|
||||||
|
|
||||||
## Run the app
|
## Run the app
|
||||||
|
|
||||||
|
Install Yarn
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install --g yarn
|
||||||
|
```
|
||||||
|
|
||||||
|
Build and run:
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn && yarn start
|
yarn && yarn start
|
||||||
```
|
```
|
||||||
@ -18,7 +26,7 @@ Move your cursor around to see the mask prediction update in real time.
|
|||||||
|
|
||||||
In the [ONNX Model Example notebook](https://github.com/facebookresearch/segment-anything/blob/main/notebooks/onnx_model_example.ipynb) upload the image of your choice and generate and save corresponding embedding.
|
In the [ONNX Model Example notebook](https://github.com/facebookresearch/segment-anything/blob/main/notebooks/onnx_model_example.ipynb) upload the image of your choice and generate and save corresponding embedding.
|
||||||
|
|
||||||
Initialize the predictor
|
Initialize the predictor:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
checkpoint = "sam_vit_h_4b8939.pth"
|
checkpoint = "sam_vit_h_4b8939.pth"
|
||||||
@ -28,7 +36,7 @@ sam.to(device='cuda')
|
|||||||
predictor = SamPredictor(sam)
|
predictor = SamPredictor(sam)
|
||||||
```
|
```
|
||||||
|
|
||||||
Set the new image and export the embedding
|
Set the new image and export the embedding:
|
||||||
|
|
||||||
```
|
```
|
||||||
image = cv2.imread('src/assets/dogs.jpg')
|
image = cv2.imread('src/assets/dogs.jpg')
|
||||||
@ -37,7 +45,7 @@ image_embedding = predictor.get_image_embedding().cpu().numpy()
|
|||||||
np.save("dogs_embedding.npy", image_embedding)
|
np.save("dogs_embedding.npy", image_embedding)
|
||||||
```
|
```
|
||||||
|
|
||||||
Save the new image and embedding in `/assets/data`.
|
Save the new image and embedding in `src/assets/data`.
|
||||||
|
|
||||||
## Export the ONNX model
|
## Export the ONNX model
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import { InferenceSession, Tensor } from "onnxruntime-web";
|
import { InferenceSession, Tensor } from "onnxruntime-web";
|
||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import "./assets/scss/App.scss";
|
import "./assets/scss/App.scss";
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import * as _ from "underscore";
|
import * as _ from "underscore";
|
||||||
import Tool from "./Tool";
|
import Tool from "./Tool";
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import AppContext from "./hooks/createContext";
|
import AppContext from "./hooks/createContext";
|
||||||
import { ToolProps } from "./helpers/Interfaces";
|
import { ToolProps } from "./helpers/Interfaces";
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import { Tensor } from "onnxruntime-web";
|
import { Tensor } from "onnxruntime-web";
|
||||||
|
|
||||||
export interface modelScaleProps {
|
export interface modelScaleProps {
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
// Functions for handling mask output from the ONNX model
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
// Convert the onnx model mask prediction to ImageData
|
// Convert the onnx model mask prediction to ImageData
|
||||||
function arrayToImageData(input: any, width: number, height: number) {
|
function arrayToImageData(input: any, width: number, height: number) {
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import { Tensor } from "onnxruntime-web";
|
import { Tensor } from "onnxruntime-web";
|
||||||
import { modeDataProps } from "./Interfaces";
|
import { modeDataProps } from "./Interfaces";
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
|
|
||||||
// Helper function for handling image scaling needed for SAM
|
// Helper function for handling image scaling needed for SAM
|
||||||
const handleImageScale = (image: HTMLImageElement) => {
|
const handleImageScale = (image: HTMLImageElement) => {
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { modelInputProps } from "../helpers/Interfaces";
|
import { modelInputProps } from "../helpers/Interfaces";
|
||||||
import AppContext from "./createContext";
|
import AppContext from "./createContext";
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import { createContext } from "react";
|
import { createContext } from "react";
|
||||||
import { modelInputProps } from "../helpers/Interfaces";
|
import { modelInputProps } from "../helpers/Interfaces";
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// This source code is licensed under the license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import AppContextProvider from "./components/hooks/context";
|
import AppContextProvider from "./components/hooks/context";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user