Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Oct 8, 2025

Changes:

  • update camera-tresholding to unstable API (the file looked almost 1:1 like chroma-keying so I guess why not differentiate it a bit),
  • add background-segmentation example, which uses ONNX runtime with unet2p model. It copies the camera fee, blurs it and selects either blurred or unblurred pixels based on the mask generated by the model.

ONNX has some issues with providing it with a device (microsoft/onnxruntime#26107). I monkey-patched some requests, and I clean this up in cleanUp.

ONNX with WebGPU does not yet work on Safari (microsoft/onnxruntime#26480), so I just throw an error.

On my phone, it works in ~1fps and is unusable, but on one of the shared devices I borrowed (Samsung Galaxy X Fold 5) it worked perfectly fine.

@aleksanderkatan aleksanderkatan linked an issue Oct 8, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Oct 8, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@68d58ecf40cd7ebf85afa60857451ec2bbcdc5e7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@68d58ecf40cd7ebf85afa60857451ec2bbcdc5e7
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@68d58ecf40cd7ebf85afa60857451ec2bbcdc5e7

benchmark
view benchmark

commit
view commit

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 15 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 15 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review November 3, 2025 16:11
Copy link
Contributor

@lursz lursz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

}

// monkey patching ONNX: https://github.com/microsoft/onnxruntime/issues/26107
const oldRequestAdapter = navigator.gpu.requestAdapter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap it in try block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

});

const feeds = { 'input.1': myPreAllocatedInputTensor };
const fetches = { '1959': myPreAllocatedOutputTensor };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 1959?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk
the outputs are named 1959, 1960..., this was the first one.

"monaco-editor": "^0.53.0",
"morphcharts": "^1.3.2",
"motion": "^12.23.24",
"onnxruntime-web": "1.23.0-dev.20250917-21fbad8a65",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump reminder (when patched)

};

const tileData = tgpu.workgroupVar(d.arrayOf(d.arrayOf(d.vec3f, 128), 4));
export const computeFn = tgpu['~unstable'].computeFn({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my mobile device (Android 16, Snapdragon 888, any browser), masking doesn't quite work
Screenshot_20251112-145626_Chrome

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☠️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to find some reason behind this, and I can't find anything. The resolution is not a problem, rewriting the video frame to a new texture also didn't help. The mask just is like this on your phone. This might be an onnx web runner issue.

@aleksanderkatan
Copy link
Contributor Author

Turns out Chrome has a built-in feature for background blur!
https://developer.chrome.com/blog/background-blur
I didn't use it though.

Copy link
Contributor

@lursz lursz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@aleksanderkatan aleksanderkatan merged commit 6918555 into main Nov 18, 2025
3 checks passed
@aleksanderkatan aleksanderkatan deleted the docs/binary-image-segmentation-example branch November 20, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: Binary image segmentation example

3 participants