Unable to run MP3ToVec.py
I was able to install all the packages on Windows, no issues (although pandas was a bit pain in the neck, but managed to install the specified version), all pip packages are resolved...
But when I try to run the command python MP3ToVec.py Pickles mp3tovec --scan D:\Music I get following error:
File "MP3ToVec.py", line 42, in <module>
model = load_model(model_file)
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\saving\save.py", line 184, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py", line 194, in load_model_from_hdf5
training_config, custom_objects))
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\saving\saving_utils.py", line 215, in compile_args_from_training_config
loss = _deserialize_nested_config(losses.deserialize, loss_config)
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\saving\saving_utils.py", line 255, in _deserialize_nested_config
return deserialize_fn(config)
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\losses.py", line 1835, in deserialize
printable_module_name='loss function')
File "C:\Users\Carlos\Anaconda3\envs\deejai\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 392, in deserialize_keras_object
raise ValueError('Unknown ' + printable_module_name + ':' + object_name)
ValueError: Unknown loss function:cosine_proximity
I searched a bit here and there and found something promising
It says to modify the load_model and make it look like load_model(model_file, compile=False), so I did that, but I got yet another error this time:
Traceback (most recent call last):
File "MP3ToVec.py", line 48, in <module>
n_mels = model.layers[0].input_shape[1]
IndexError: list index out of range
Apparently, the model.layers[0].input_shape is a list of only one element (instead of at least 3, the next line was accessing input_shape[2].
At this point I am uncertain what it is I am doing wrong, any ideas? Thanks!
Using the ,compile=False) I saw same error. I fixed by: After loading model model = load_model(model_file,compile=False) shape = model.layers[0].input_shape[0] Then n_mels = shape[1] slice_size = shape[2] Seemed to fix it for me
Sorry you are having problems. TensorFlow has moved on a lot since I did this project. Apart from saying "it works for me" which isn't too helpful, you can try
from tensorflow.compat.v1.keras.losses import cosine_proximity model = load_model( model_file, custom_objects={ 'cosine_proximity': tf.compat.v1.keras.losses.cosine_proximity })
Out of interest, have you tried running it in a Python virtual environment with the packages installed as per the requirements.txt file? You will have to use Python 3.8 for this. I beleive it works for this combination, but I haven't updated it to keep up with the latest versions of Tensorflow. In other repos (deej-ai.online-app) I have had to make the above changes, but I'm not sure why you have to make the other modification regarding the input shape - I haven't had to do that. If enough people find it useful, I will update the repo to work with Tensforflow > 2.2.
Thanks for reporting this and trying to sort it out yourself first. Good luck!
The changes I made and posted got it all working when combined with the compile=False change to load_model. I did not run a Python virtual environment.