deezer / spleeter

Deezer source separation library including pretrained models.
https://research.deezer.com/projects/spleeter.html
MIT License
25.84k stars 2.83k forks source link

[Discussion] successfull tf2 automatic upgrade #439

Open ltetrel opened 4 years ago

ltetrel commented 4 years ago

Hi,

Just wanted to let you know that I upgraded spleeter with tensorflow 2 using tf_upgrade_v2 --intree ./ --outtree ./ --reportfile report.txt from tf2 branch and it is working fine.

Of course the script just replace older function by tf.compat.v1 so it is not the most optimal option..

Here is the report:

TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 31 files
Detected 3 issues that require attention
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
File: ./spleeter/separator.py
--------------------------------------------------------------------------------
./spleeter/separator.py:325:16: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------
File: ./tests/test_ffmpeg_adapter.py
--------------------------------------------------------------------------------
./tests/test_ffmpeg_adapter.py:79:8: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------
File: ./tests/test_eval.py
--------------------------------------------------------------------------------
./tests/test_eval.py:68:12: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
================================================================================
Detailed log follows:

================================================================================
================================================================================
Input tree: './'
================================================================================
--------------------------------------------------------------------------------
Processing file './setup.py'
 outputting to './setup.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/dataset.py'
 outputting to './spleeter/dataset.py'
--------------------------------------------------------------------------------

176:20: INFO: Added keywords to args of function 'tf.shape'
241:53: INFO: Renamed 'tf.string_join' to 'tf.strings.join'
256:19: INFO: Added keywords to args of function 'tf.reduce_min'
257:16: INFO: Added keywords to args of function 'tf.shape'
266:15: INFO: Added keywords to args of function 'tf.reduce_any'
267:12: INFO: Added keywords to args of function 'tf.shape'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/__init__.py'
 outputting to './spleeter/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/__main__.py'
 outputting to './spleeter/__main__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/separator.py'
 outputting to './spleeter/separator.py'
--------------------------------------------------------------------------------

325:16: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/resources/__init__.py'
 outputting to './spleeter/resources/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/utils/configuration.py'
 outputting to './spleeter/utils/configuration.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/utils/logging.py'
 outputting to './spleeter/utils/logging.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/utils/__init__.py'
 outputting to './spleeter/utils/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/utils/tensor.py'
 outputting to './spleeter/utils/tensor.py'
--------------------------------------------------------------------------------

46:19: INFO: Added keywords to args of function 'tf.shape'
72:17: INFO: Added keywords to args of function 'tf.reduce_min'
73:17: INFO: Added keywords to args of function 'tf.reduce_max'
115:35: INFO: Added keywords to args of function 'tf.shape'
117:13: INFO: Added keywords to args of function 'tf.pad'
120:13: INFO: Added keywords to args of function 'tf.shape'
124:35: INFO: Added keywords to args of function 'tf.shape'
135:17: INFO: Added keywords to args of function 'tf.shape'
140:16: INFO: Added keywords to args of function 'tf.shape'
178:53: INFO: Added keywords to args of function 'tf.shape'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/utils/estimator.py'
 outputting to './spleeter/utils/estimator.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/__init__.py'
 outputting to './spleeter/model/__init__.py'
--------------------------------------------------------------------------------

221:22: INFO: Added keywords to args of function 'tf.reduce_mean'
226:22: INFO: Added keywords to args of function 'tf.reduce_mean'
227:20: INFO: Added keywords to args of function 'tf.reduce_mean'
227:20: INFO: Renamed keyword argument for tf.reduce_mean from keep_dims to keepdims
236:15: INFO: Added keywords to args of function 'tf.reduce_sum'
278:27: INFO: Added keywords to args of function 'tf.transpose'
280:20: INFO: Added keywords to args of function 'tf.transpose'
335:12: INFO: Added keywords to args of function 'tf.transpose'
341:19: INFO: Added keywords to args of function 'tf.transpose'
343:24: INFO: Added keywords to args of function 'tf.shape'
362:30: INFO: Added keywords to args of function 'tf.shape'
388:28: INFO: Added keywords to args of function 'tf.reduce_mean'
392:25: INFO: Added keywords to args of function 'tf.shape'
412:21: INFO: Added keywords to args of function 'tf.reduce_sum'
425:24: INFO: Added keywords to args of function 'tf.shape'
433:31: INFO: Added keywords to args of function 'tf.shape'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/provider/__init__.py'
 outputting to './spleeter/model/provider/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/provider/github.py'
 outputting to './spleeter/model/provider/github.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/functions/blstm.py'
 outputting to './spleeter/model/functions/blstm.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/functions/__init__.py'
 outputting to './spleeter/model/functions/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/model/functions/unet.py'
 outputting to './spleeter/model/functions/unet.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/audio/adapter.py'
 outputting to './spleeter/audio/adapter.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/audio/__init__.py'
 outputting to './spleeter/audio/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/audio/ffmpeg.py'
 outputting to './spleeter/audio/ffmpeg.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/audio/spectrogram.py'
 outputting to './spleeter/audio/spectrogram.py'
--------------------------------------------------------------------------------

37:18: INFO: Added keywords to args of function 'tf.transpose'
39:12: INFO: Added keywords to args of function 'tf.transpose'
62:8: INFO: Added keywords to args of function 'tf.shape'
64:8: INFO: Added keywords to args of function 'tf.shape'
65:14: INFO: Removed argument align_corners for function tf.image.resize_images
65:14: INFO: Renamed 'tf.image.resize_images' to 'tf.image.resize'
70:11: INFO: Renamed 'tf.image.resize_image_with_crop_or_pad' to 'tf.image.resize_with_crop_or_pad'
83:13: INFO: Renamed 'tf.random_uniform' to 'tf.random.uniform'
102:8: INFO: Added keywords to args of function 'tf.shape'
103:8: INFO: Added keywords to args of function 'tf.shape'
105:14: INFO: Removed argument align_corners for function tf.image.resize_images
105:14: INFO: Renamed 'tf.image.resize_images' to 'tf.image.resize'
111:11: INFO: Added keywords to args of function 'tf.pad'
125:21: INFO: Renamed 'tf.random_uniform' to 'tf.random.uniform'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/audio/convertor.py'
 outputting to './spleeter/audio/convertor.py'
--------------------------------------------------------------------------------

26:11: INFO: Added keywords to args of function 'tf.cond'
27:8: INFO: Added keywords to args of function 'tf.shape'
74:25: INFO: Added keywords to args of function 'tf.reduce_max'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/commands/evaluate.py'
 outputting to './spleeter/commands/evaluate.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/commands/__init__.py'
 outputting to './spleeter/commands/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/commands/separate.py'
 outputting to './spleeter/commands/separate.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './spleeter/commands/train.py'
 outputting to './spleeter/commands/train.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './tests/test_github_model_provider.py'
 outputting to './tests/test_github_model_provider.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './tests/__init__.py'
 outputting to './tests/__init__.py'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './tests/test_ffmpeg_adapter.py'
 outputting to './tests/test_ffmpeg_adapter.py'
--------------------------------------------------------------------------------

79:8: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './tests/test_separator.py'
 outputting to './tests/test_separator.py'
--------------------------------------------------------------------------------

45:9: INFO: Renamed 'tf.Session' to 'tf.compat.v1.Session'
66:9: INFO: Renamed 'tf.Session' to 'tf.compat.v1.Session'
83:9: INFO: Renamed 'tf.Session' to 'tf.compat.v1.Session'
101:9: INFO: Renamed 'tf.Session' to 'tf.compat.v1.Session'
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Processing file './tests/test_eval.py'
 outputting to './tests/test_eval.py'
--------------------------------------------------------------------------------

68:12: WARNING: *.save requires manual check. (This warning is only applicable if the code saves a tf.Keras model) Keras model.save now saves to the Tensorflow SavedModel format by default, instead of HDF5. To continue saving to HDF5, add the argument save_format='h5' to the save() function.
--------------------------------------------------------------------------------
aidv commented 4 years ago

Great to know, but what benefits do we get out of this?

agur commented 3 years ago

Great to know, but what benefits do we get out of this?

@aidv Believe this could TF2 models have various benefits. One we're looking at is since TF2 is the best route to tflite and mobile support. There surely are other reasons to go TF2.

agur commented 3 years ago

Hi,

Just wanted to let you know that I upgraded spleeter with tensorflow 2 using tf_upgrade_v2 --intree ./ --outtree ./ --reportfile report.txt from tf2 branch and it is working fine.

...

@ltetrel - Thanks, would like to try it out and see if the quality is good enough at least for now until we manage to re-train in full for TF2 (#477).

I see that tf2 branch is already merged back to master (60ef2778f228bb4a3b3a818c7ea7979a3934faca)

Questions:

  1. With that upgrade command/process can I take the pretrained_models/2stem and convert just that one to TF2?

  2. What's the quality difference when you say: Of course the script just replace older function by tf.compat.v1 so it is not the most optimal option..? Was it measured, or do you have a sense?

ltetrel commented 3 years ago

Hi @agur, I did that a while ago but I will try to be the more accurate as possible. I did not compare the quality/benchmark the speed gain between tf1 and tf2. For me it was mostly the only way to get spleeter to work since I have cuda 10 (nvidia rtx card).

  1. I am using the same pre-trained model and it worked as is without converting it to a tf2 model.
  2. What I meant by this, is that it is always better to use native tf2 function to gain the advantage of the update, instead of relying on old function (tf.compat.v1 is just a fork of the old tf1 code). One of the major update is an improvement in the graph build and computation, you can still check here all the major differences: https://www.tensorflow.org/guide/effective_tf2
agur commented 3 years ago

@ltetrel - thanks, not sure that your method is relevant to those needing mobile and tflite. If it is relevant, or if there is another way to convert the existing pretrained_models/2stem to TF2 format which is reasonably easy - that would be a good shorter term fix for those who want mobile. @VVasanth - plz lmk if you can add here.

VVasanth commented 3 years ago

@ltetrel - If I understand correctly, you have used the above command to migrate the code from TF1 to TF2...and you were able to execute the code without issues...pls confirm on this...

By any chance, did you try to migrate the Spleeter models into TF2 format of 'savedmodel'? If yes, pls let us know...we are working towards porting spleeter model into edge devices by converting them into TFLite format...Thanks!

ltetrel commented 3 years ago

@VVasanth Yes I was able to use this code, and I am still using it on my gpu by the way. As I said previously, sadly I did not migrated the spleeter model.

Good luck when porting spleeter into a mobile format, this has a lot of opportunity for the deezer app, allowing any user to listen to a song without the instruments for example!