essentia icon indicating copy to clipboard operation
essentia copied to clipboard

iOS build broken (Tensorflow dependency)

Open LDMFD opened this issue 1 year ago • 7 comments

Building with python3 waf configure --cross-compile-ios --lightweight= --fft=ACCELERATE --build-static --ignore-algos=NNLSChroma

I needed to comment out two sections in types.h;

  1. Relating to string comparison;
    • I needed to comment out the function case_insensitive_str_cmp() - this may be related to https://stackoverflow.com/questions/22386882/why-have-unary-function-binary-function-been-removed-from-c11
  2. Relating to Tensor;
    • I needed to comment out:
      • #include <unsupported/Eigen/CXX11/Tensor>
      • The 6 or so Tensor types (starting from Alias for Eigen::Tensor.).

This is despite Tensor apparently being ignored; the build log gives:

- Essentia is configured without Tensorflow.
  The following algorithms will be ignored: ['TensorflowPredict', 'TensorflowPredictMusiCNN', 
'TensorflowPredictVGGish', 'TensorflowPredictTempoCNN', 'TensorflowPredictCREPE', 
'PitchCREPE', 'TempoCNN', 'TensorflowPredictEffnetDiscogs', 'TensorflowPredict2D', 'TensorflowPredictFSDSINet']

Is there any fix already present that I simply need to enable?

I'm building on MacOS Ventura 13.4, with Xcode 15.0 beta 2.

LDMFD avatar Jul 10 '23 04:07 LDMFD

Update: as the Stackoverflow post hints at, switching the C++ dialect to gnu++14 (in Xcode) solves the problem for the string comparison function.

LDMFD avatar Jul 10 '23 04:07 LDMFD

hi @LDMFD, right, the Tensorflow-related algorithms are ignored by default, but we don't have a mechanism to prevent creating the Tensor types.

I can see that similar problems occur in OpenCV, and they now support deactivating the Eigen Tensors.

We could be interested in doing the same.

palonso avatar Jul 12 '23 07:07 palonso

Hi @palonso thank you for the feedback. I hit this problem again after including essentiamath.h. What is the correct fix for iOS builds?

I built with --with-tensorflow but looking at the missing symbols, it seems Essentia depends on the full Tensorflow library, so:

  1. Are the Tensor-based features of Essentia available for mobile?
  2. Regardless of Tensorflow, is there a known build working for iOS? (if so, what am I missing)

I am looking for pitch detection primarily.

LDMFD avatar Jul 16 '23 17:07 LDMFD

@LDMFD, Essentia only depends on TensorFlow when using the --with-tensorflow flag. The purpose of TensorFlow is to use our Essentia Models, so for your use case, you can build Essentia without the flag.

Since tensor-based methods are only required when using these models, we could have a directive WITH_TENSORFLOW to skip tensor-based auxiliary methods and types when TensorFlow is not required.

For now, you can just comment out these methods in essentiamath.h and the types.

palonso avatar Jul 17 '23 18:07 palonso

Appreciate the pointer - will give this a try.

LDMFD avatar Jul 18 '23 01:07 LDMFD

I'm following up here in hopes this will be useful for others. From what I can tell, Essentia with tensorflow (needed for TemopCNN) is simply incompatible with iOS. TensorFlowLite (the only supported target for iOS), has a different set of interfaces to what the TempoCNN components in Essentia use. Including the TensorFlow header path in an XCode project results in undefined symbol compiler errors.

_TF_AllocateTensor, referenced from: essentia::standard::TensorflowPredict::configure() in libessentia.a[arm64]167 . . .

It would have been useful to know about this incompatibility before wasting a day trying to make it work. Hopefully this will be useful for others.

ashayk avatar Sep 23 '23 01:09 ashayk

@ashayk We apologize for any confusion. Unfortunately, adding TensorFlowLite support is out of scope at the moment. We added a clarification to the FAQ (4c48bb1cabfd2f73f4555065806df67922c39ac0).

dbogdanov avatar Sep 27 '23 10:09 dbogdanov