gvne / spleeterpp

A C++ Inference library for the Spleeter project
MIT License
159 stars 34 forks source link

Need help with export_spleeter_models.py #24

Closed tinoucas closed 4 years ago

tinoucas commented 4 years ago

Hi,

I'm trying to export a saved model from a checkpoint (4stems from deezer/spleeter) with this export_spleeter_models.py (from cmake/ directory). But I end up with the following output tensors:

  The given SavedModel SignatureDef contains the following output(s):
    outputs['bass'] tensor_info:
        dtype: DT_COMPLEX64
        shape: (4, 2049, 2)
        name: mul_6:0
    outputs['drums'] tensor_info:
        dtype: DT_COMPLEX64
        shape: (4, 2049, 2)
        name: mul_5:0
    outputs['other'] tensor_info:
        dtype: DT_COMPLEX64
        shape: (4, 2049, 2)
        name: mul_7:0
    outputs['vocals'] tensor_info:
        dtype: DT_COMPLEX64
        shape: (4, 2049, 2)
        name: mul_4:0
  Method name is: tensorflow/serving/predict

Everything is wrong: type/dimensions/name... Eventhough, the spleeter checkpoint version from github match (v1.4.0)

I only managed to launch this script with python 3.7 on macOS (the only version of python I found with both spleeter and tensorflow 1.15.2, through pip)

Any clue what might be the cause? How did you do it?

gvne commented 4 years ago

Hi @tinoucas and sorry for the delay. I'm not much available lately.
To check how I use that script, you should take a look at the add_spleeter.cmake file.

If you don't want to bother with the export, I also uploaded deezer's checkpoints model after conversion right here.

Hope this helps !

tinoucas commented 4 years ago

Hi @gvne That's what I started with: read the cmake to find out how to use it. Nevertheless, I managed to export it without this script: Using tf.compat.v1.saved_model.builder.SavedModelBuilder and add_meta_graph_and_variables, and recreating the signature manually. Also, this method does not require the spleeter package. BTW: my goal was to convert it to TensorFlow-lite, and it works! 😃 (the models you exported caused errors with the converter: audio_id had no shape)

gvne commented 4 years ago

Great to see you found another way.

Happy coding !

oluwabajio commented 4 years ago

@tinoucas Please i have been looking fo how to export the models to tflite and i would gladly appreciate if you can assist me on how you achieved that.

RufusMall commented 4 years ago

Hi @gvne That's what I started with: read the cmake to find out how to use it. Nevertheless, I managed to export it without this script: Using tf.compat.v1.saved_model.builder.SavedModelBuilder and add_meta_graph_and_variables, and recreating the signature manually. Also, this method does not require the spleeter package. BTW: my goal was to convert it to TensorFlow-lite, and it works! 😃 (the models you exported caused errors with the converter: audio_id had no shape)

Wow do you think you could share this?

I have been trying to get spleeter to run on mobile (iOS) by using going back to the correct version of tensorflow 1.x and trying to rebuild it for iOS with the correct operations/kernals added. After I got all that done I realised a bunch of the bundle loading methods have not been implemented for that platform -_- in this older version.

tinoucas commented 4 years ago

For all those wondering, I've put my scripts and some info for this in a new repo here: spleeter-tflite-convert

RufusMall commented 4 years ago

Your link looks correct but when you click on it - it navigates to the wrong page.

Correct link

^^ Correct link

Also thanks very much! Can't wait to check this out :D.

tinoucas commented 4 years ago

Sorry about that (I fixed the link)

jinay1991 commented 3 years ago

For all those wondering, I've put my scripts and some info for this in a new repo here: spleeter-tflite-convert

Thank you very much for your support @tinoucas.

For those looking for pre-converted binaries, they can download this consist of all the models (2stems, 4stems and 5stems - SavedModel + TFLite) - Generated based on the scripts provided by @tinoucas and official checkpoints provided by deezer/spleeter

oluwabajio commented 3 years ago

Thanks @jinay1991 for your help. I am implementing this model in an android app. What are the audio pre-processing I need to do to the input audio file (mp3) before passing to the tflite interpreter. And also what are the post-processing I need to do to the output

theblissprogrammer commented 3 years ago

@tinoucas do you know how you can convert the saved models to tfjs graph model? I tried using the tensorflowjs_converter and it throws an error "ValueError: index can't contain negative values" with those saved models.