Skip to content

Commit

Permalink
chore: dev
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Dec 6, 2023
1 parent 9af84b1 commit d33c744
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
<title>Playground</title>
</head>
<body>
<div>Playground</div>

<script type="module" async>
import { removeBackground } from './dist'
import { removeBackground } from './src'

const imageSource = '/examples/example.jpg'

const blob = await removeBackground('/docs/assets/example.jpg', {
const blob = await removeBackground(imageSource, {
debug: true,
model: '/models/u2net.onnx',
resolution: 320,
model: '/models/small.onnx',
resolution: 1024,
wasmPaths: {
'ort-wasm-simd.wasm': './node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm',
},
})

const img1 = new Image()
img1.src = '/docs/assets/example.jpg'
img1.src = imageSource
img1.width = '100'
document.body.append(img1)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dist"
],
"scripts": {
"dev": "rollup -cw & vite",
"dev": "vite",
"lint": "eslint src",
"test": "vitest",
"build": "rimraf dist && rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion src/remove-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function removeBackground(
resized.toBchwImageTensor().toTensor(),
])
model.release()
debug && consoleDebug('Compute inference completion', result)

const stride = resolution * resolution
switch (options.output ?? 'foreground') {
Expand Down Expand Up @@ -64,6 +65,5 @@ export async function removeBackground(
break
}

debug && consoleDebug('Compute inference completion')
return await resized.resize(imageTensor.dims[1], imageTensor.dims[0]).toBlob()
}

0 comments on commit d33c744

Please sign in to comment.