Has anyone managed to integrate Tensorflow API in a juce project?

I can get the c++ API in fine on windows but struggling to know what to do with OSX and projucer…

Did you managed to run this? … I have integrated the libraries, and standalone runs fine. But when I compile AU, I can’t get it to open it in pluginval or logic. BUT VST3 works fine

Hi Turrubiates, I’m currently trying to integrate the tensorflow API to Juce too, but I’m kind of struggling. I followed several tutorials on how to download and use the C API but nothing is working. I also posted this topic on stack overflow.

Is there any way you could help me? I would be very very very grateful.

Can you first be sure you’ve followed the official C install from the Tensorflow project → Install TensorFlow for C

Secondly there should be nothing special in integrating with JUCE. So long as you’ve got it working in C I can’t see a problem. Just pass the data from your JUCE app thru TF and have your TF functions or whatever algorithm return the values back to your JUCE app.

can you give more info?

Hello SourGummi, thank you very much for your reply! The official tutorial you joined is the first one I followed. And the quick test at the end of the tutorial to check if the installation was successful went well too.
So in my Xcode project I can do : #include <tensorflow/c/c_api.h>
But I don’t understand how I can declare a variable of type tensorflow::Scope for example or any other TF ADT.
I can’t get using namespace tensorflow; to work.
Any idea?

Namespaces (such as namespace tensorflow) and classes (such as tensorflow:Scope) don’t exist in C.
If you want to use these, you need to include and use the C++ API.

Hi, yes that what I thought too, but on tensorflow’s website they don’t provide any installation guidelines for the C++ API.

Does that mean that it should be downloaded like the python API through pip? ( pip install tensorflow ) It’s weird to install a C++ library using pip, but I guess it could make sense since most of the python core is written in C++.

But then how should I do to access those functions in my XCode project?

We open sourced our recent “Vibrary” project that links Tensorflow into a JUCE app – you may be able to use that code and its docs as a reference to help you.

I should get someone to write this up as a blog post to point folks at.

Start here: GitHub - artandlogic/vibrary

4 Likes

Very much appreciated!

1 Like

Hi there,

i am also facing this problem. The artandlogic/vibrary project sounded so interesting and helpful - unfortunately it seems to be offline.

Anybody else with some example project / code?

If you’re just looking to integrate an existing C++ library (such as Tensorflow). Likely the main things you need to do are:

  1. Save the library to some folder on your computer. You could save this inside your JUCE project folder under some subfolder like “ThirdParty” or “External”.
  2. Tell your Projucer or your IDE/compiler about the folder you want to include library files from. In the Projucer project settings look for “Header Search Paths” and add the path to the library folder here. You may want to make this a relative path which may look something like ../../External/tensorflow depending on your specific directory setup. In this example, now all files directly in the folder External/tensorflow can be included with #include <ATensorflowFileName.h>. You can manually add Header Search Paths in your IDE, but if you add it to Projucer, these paths will export to any IDE you are using.
  3. (Bonus) You could even add the library folder to Git Submodules or Git Subtrees to keep it in version control referencing the original Git repository the library comes from so you can easily update the library later when a new version or specific fix comes out.

Sometimes libraries require more setup, but this is usually the bare minimum to get a C++ library integrated. Maybe you already knew about the steps I listed above, but thought I would share just in case.

I would also recommend cppflow … GitHub - serizba/cppflow: Run TensorFlow models in C++ without installation and without Bazel

2 Likes

Weird – I’m no longer at Art+Logic, so I had no idea that it had been taken down. The Vibrary repo is still available through Dr. Scott Hawley, the researcher who we worked with on that project:

1 Like

In case someone Google’s this in the future: We used Bazel to build a cross-platform static library which exposes our own extern "C" API and uses TensorFlow Lite for execution under the hood. We also used bazel helpers to statically embed the tflite AI model into that lib. Then linking against that static library from within Introjucer was a piece of cake. Plus this made it much easier to run automated tests to confirm the AI behaving as it should.

These days tensorflow’s CMake support is quite good, so developers getting started with JUCE and tf for the first time will probably want to go for this over Bazel. I can confirm things are working just fine with JUCE 7.