Giter Club home page Giter Club logo

Comments (14)

asus4 avatar asus4 commented on May 16, 2024 2

This feature is supported in the TFLite C++ API, but not yet in the C API that is used by Unity.
When I have time, I will try to fix the TFLite C API.

from tf-lite-unity-sample.

WHSnyder avatar WHSnyder commented on May 16, 2024 1

@asus4 Wow I jumped the gun on that one, took a quick glance at the description and thought it depended on missing functionality in TFLite itself. Guess I got too excited that my project might be directly relevant 😩. I suppose there's still a need in TFLite for a bindTensorToGLTexture function to avoid the texture to buffer copy, though it's not expensive in the grand scheme of things... I'm still absorbing the backend structure of TFLite GPU delegates, there's undocumented functionality I keep finding like the CLDelegate's BindBufferToTensor method. I'll post here again if I push any GLDelegate changes to the main TF repo

from tf-lite-unity-sample.

mathtasatlime avatar mathtasatlime commented on May 16, 2024 1

@asus4 that would be really great! This issue is the biggest source of lag in my game.

from tf-lite-unity-sample.

asus4 avatar asus4 commented on May 16, 2024 1

Working on this issue today: Modified both TensorFlow and Unity codes. and it worked with the Metal delegate now.

  • TensorFlow branch

    • Exposed the GPU buffer-binding APIs to the C framework.
  • Unity branch

    • Added a test scene to evaluate the effect of this modification.

Next step: Supports OpenGLES delegate as well.

from tf-lite-unity-sample.

WHSnyder avatar WHSnyder commented on May 16, 2024

Hi there, I wish I had seen this project a couple weeks ago! I've been working on a fork of tensorflow allowing for easy integration with rendering pipelines https://github.com/WHSnyder/tensorflow/tree/general_opengl, so pretty much this exact issue. So far I've just gotten the delegates to build for MacOS and Ubuntu and decoupled OpenGL from OpenGLES. The GL delegate works on Ubuntu now (given you have created a context beforehand) and the Metal delegate no longer crashes when used on MacOS (CoreGraphics wasn't linked in the /lite/delegates/gpu BUILD file). I also added some code to expose the Metal/GL delegates in the Python API (the pyexposure files).

However, I have not been able to get any of these delegates to work with this style transfer example https://www.tensorflow.org/lite/models/style_transfer/overview or this one https://github.com/tensorflow/examples/tree/master/lite/examples/style_transfer
I get the exact same error as discussed here tensorflow/tensorflow#32101 I've been using the Python API to create & call delegates, since that hasn't worked I've dedicated today to testing with the C++ API. Sorry to bombard you with links, once I get this worked out I'll see if I can merge it cleanly into this repo.

The GPU buffer binding you mention is only for Metal, but once I get everything working with the style transfer example I'll write a couple functions to expose the buffers for the GL delegate.

EDIT: Didn't notice the TfLiteGpuDelegateBindBufferToTensor function. Nobody seems to mention it, I'll see if I can get it working and implement a BindTextrueToTensor function for render target usage.

from tf-lite-unity-sample.

asus4 avatar asus4 commented on May 16, 2024

Hi @WHSnyder, Thank you for your interest. This repository does not contain any TensorFlow's code. Please make PR to TensorFlow repository then I'll build the shared lib 😃

from tf-lite-unity-sample.

liamwalsh avatar liamwalsh commented on May 16, 2024

For those working with ARFoundation you can indeed skip a fair few of the steps as outlined above.

from tf-lite-unity-sample.

mathtasatlime avatar mathtasatlime commented on May 16, 2024

@WHSnyder do your have any updates on that issue? atm I'm facing the problem that the readPixels functions blocks my main thread and reduces the performance to measly 15 fps... -> #96

from tf-lite-unity-sample.

stale avatar stale commented on May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from tf-lite-unity-sample.

mathtasatlime avatar mathtasatlime commented on May 16, 2024

@asus4 any new information regaring that issue?

from tf-lite-unity-sample.

mathtasatlime avatar mathtasatlime commented on May 16, 2024

really nice!

from tf-lite-unity-sample.

asus4 avatar asus4 commented on May 16, 2024

Android's GPU delegate worked as well with the following branch
https://github.com/asus4/tensorflow/tree/bindbuffer-gpudelegate

It was super tricky to figure out the correct setting in Unity
android-with-gpu-binding

We can use this feature with my branch's TensorFlow. and preparing a PR for the main repository.
tensorflow/tensorflow#49313

from tf-lite-unity-sample.

asus4 avatar asus4 commented on May 16, 2024

I suppose that multi-threaded rendering would be possible if the GPU-fence could be shared with TensorFlow. but there is no API to share it at the moment.
https://docs.unity3d.com/ScriptReference/Rendering.GraphicsFence.html

Correct me if I'm wrong, I'm a complete beginner at this.

from tf-lite-unity-sample.

asus4 avatar asus4 commented on May 16, 2024

Although the PR on TensorFlow has not merged yet, I merged these changes to proceed with this issue.

The modified TensorFlow branch ↓
https://github.com/asus4/tensorflow/tree/2.5.0-with-bindbuffer

from tf-lite-unity-sample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.