Git Product home page Git Product logo

deej-ai's Introduction

Deej-A.I.

Robert Dargavel Smith - Advanced Machine Learning end of Masters project (MBIT School, Madrid, Spain)

UPDATE: After nearly 5 years, I have finally got around to re-training the model deployed at https://deej-ai.online with a million playlists and a million tracks. The fact that people have been consistently continuing to use it is testament to how well it works, but it was about time I included tracks released since 2018! I have added a train directory to this repo where you can find a README with detailed instructions on how to obtain datasets and train your own model from scratch.

UPDATE: You can now use this model even more easily than before in the Hugging Face hub.

UPDATE: Check out the results after applying to 320,000 tracks on Spotify here. The code for the website is available here.

Motivation

There are a number of automatic DJ tools around, which cleverly match the tempo of one song with another and mix the beats. To be honest, I have always found that kind of DJ rather boring: the better they are technically, the more it sounds just like one interminable song. In my book, it's not about how you play, but what you play. I have collected many rare records over the years and done a bit of deejaying on the radio and in clubs. I can almost instantly tell whether I am going to like a song or not just by listening to it for a few seconds. Or, if a song is playing, one that would go well with it usually comes to mind immediately. I thought that artificial intelligence could be applied to this "music intuition" as a music recommendation system based on simply listening to a song (and, of course, having an encyclopaedic knowledge of music).

Some years ago, the iPod had a very cool feature called Genius, which created a playlist on-the-fly based on a few example songs. Apple decided to remove this functionality (although it is still available in iTunes), presumably in a move to persuade people to subscribe to their music streaming service. Of course, Spotify now offers this functionality but, personally, I find the recommendations that it makes to be, at best, music I already know and, at worst, rather commercial and uncreative. I have a large library of music and I miss having a simple way to say "keep playing songs like this" (especially when I am driving) and something to help me discover new music, even within my own collection. I spent some time looking for an alternative solution but didn't find anything.

Implementation details

A common approach is to use music genres to classify music, but I find this to be too simplistic and constraining. Is Roxanne by The Police reggae, pop or rock? And what about all the constantly evolving subdivisions of electronic music? I felt it necessary to find a higher dimensional, more continuous description of music and one that did not require labelling each track (i.e., an unsupervised learning approach).

The first thing I did was to scrape as many playlists from Spotify as possible. (Unfortunately, I had the idea to work on this after a competition to do something similar had already been closed, in which access to a million songs was granted.) The idea was that grouping by playlists would give some context or meaning to the individual songs - for example, "80s disco music" or "My favourite songs for the beach". People tend to make playlists of songs by similar artists, with a similar mood, style, genre or for a particular purpose (e.g., for a workout in the gym). Unfortunately, the Spotify API doesn't make it particularly easy to download playlists, so the method was rather crude: I searched for all the playlists with the letter 'a' in the name, the letter 'b', and so on, up to 'Z'. In this way, I managed to grab 240,000 playlists comprising 4 million unique songs. I deliberately excluded all playlists curated by Spotify as these were particularly commercial (I believe that artists can pay to feature in them).

Then, I created an embedding ("Track2Vec") of these songs using the Word2Vec algorithm by considering each song as a "word" and each playlist as a "sentence". (If you can believe me, I had the same idea independently of these guys.) I found 100 dimensions to be a good size. Given a particular song, the model was able to convincingly suggest Spotify songs by the same artist or similar, or from the same period and genre. As the number of unique songs was huge, I limited the "vocabulary" to those which appeared in at least 10 playlists, leaving me with 450,000 tracks.

One nice thing about the Spotify API is that it provides a URL for most songs, which allows you to download a 30 second sample as an MP3. I downloaded all of these MP3s and converted them to a Mel Spectrogram - a compact representation of each song, which supposedly reflects how the human ear responds to sound. In the same way as a human being can think of related music just by listening to a few seconds of a song, I thought that a window of just 5 seconds would be enough to capture the gist of a song. Even with such a limited representation, the zipped size of all the spectrograms came to 4.5 gigabytes!

The next step was to try to use the information gleaned from Spotify to extract features from the spectrograms in order to meaningfully relate them to each other. I trained a convolutional neural network to reproduce as closely as possible (in cosine proximity) the Track2Vec vector (output y) corresponding to a given spectrogram (input x). I tried both one dimensional (in the time axis) and two dimensional convolutional networks and compared the results to a baseline model. The baseline model tried to come up with the closest Track2Vec vector without actually listening to the music. This led to a song that, in theory, everybody should either like (or hate) a little bit ;-) (SBTRKT - Sanctuary), with a cosine proximity of 0.52. The best score I was able to obtain with the validation data before overfitting set in was 0.70. With a 300-dimensional embedding, the validation score was better, but so was that of the baseline: I felt it was more important to have a lower baseline score and a bigger difference between the two, reflecting a latent representation with more diversity and capacity for discrimination. The score, of course, is still very low, but it is not really reasonable to expect that a spectrogram can capture the similarities between songs that human beings group together based on cultural and historical factors. Also, some songs were quite badly represented by the 5 second window (for example, in the case of "Don't stop me now" by Queen, this section corresponded to Brian May's guitar solo...). I played around with an Auto-Encoder and a Variational Auto-Encoder in the hope of forcing the internal latent representation of the spectrograms to be more continuous, disentangled and therefore meaningful. The initial results appeared to indicate that a two dimensional convolutional network is better at capturing the information contained in the spectrograms. I also considered training a Siamese network to directly compare two spectrograms. I've left these ideas for possible future research.

Finally, with a library of MP3 files, I mapped each MP3 to a series of Track2Vec vectors for each 5 second time slice. Most songs vary significantly from beginning to end and so the slice by slice recommendations are all over the place. In the same way as we can apply a Doc2Vec model to compare similar documents, I calculated a "MP3ToVec" vector for each MP3, including each constituent Track2Vec vector according to its TF-IDF (Term Frequency, Inverse Document Frequency) weight. This scheme gives more importance to recommendations which are frequent and specific to a particular song. As this is an algorithm, it was necessary to break the library of MP3s into batches of 100 (my 8,000 MP3s would have taken 10 days to process otherwise!). I checked that this had a negligible impact on the calculated vectors.

Results

You can see the some of the results at the end of this workbook and judge them for yourself. It is particularly good at recognizing classical music, spoken word, hip-hop and electronic music. In fact, I was so surprised by how well it worked, that I started to wonder how much was due to the TF-IDF algorithm and how much was due to the neural network. So I created another baseline model using the neural network with randomly initialized weights to map the spectrograms to vectors. I found that this baseline model was good at spotting genres and structurally similar songs, but, when in doubt, would propose something totally inappropriate. In these cases, the trained neural net seemed to choose something that had a similar energy, mood or instrumentation. In many ways, this was exactly what I was looking for: a creative approach that transcended rigid genre boundaries. By playing around with the parameter which determines whether two vectors are the same or not for the purposes of the TF-IDF algorithm, it is possible to find a good trade-off between the genre (global) and the "feel" (local) characteristics. I also compared the results to playlists generated by Genius in iTunes and, although it is very subjective, I felt that Genius was sticking to genres even if the songs didn't quite go together, and came up with less "inspired" choices. Perhaps a crowd sourced "Coca Cola" test is called for to be the final judge.

Certainly, given the limitations of data, computing power and time, I think that the results serve as a proof of concept.

Applications

Apart from the original idea of an automatic (radio as opposed to club) DJ, there are several other interesting things you can do. For example, as the vector mapping is continuous, you can easily create a playlist which smoothly "joins the dots" between one song and another, passing through as many waypoints as you like. For example, you could travel from soul to techno via funk and drum 'n' bass. Or from rock to opera :-).

Another simple idea is to listen to music using a microphone and to propose a set of next songs to play on the fly. Rather than comparing with the overall MP3ToVec, it might be more appropriate to just take into account the beginning of each song, so that the music segues more naturally from one track to another.

Try it out for yourself

Once you have installed the required python packages with

pip install -r requirements.txt

and downloaded the model weights to the directory where you have the python files, you can process your library of MP3s (and M4As). Simply run the following command and wait...

python MP3ToVec.py Pickles mp3tovec --scan c:/your_music_library

It will create a directory called "Pickles" and, within the subdirectory "mp3tovecs" a file called "mp3tovec.p". Once this has completed, you can try it out with

python Deej-A.I.py Pickles mp3tovec

Then go to http://localhost:8050 in your browser. If you add the parameter --demo 5, you don't have to wait until the end of each song. Simply load an MP3 or M4A on which you wish to base the playlist; it doesn't necessarily have to be one from your music library. Finally, there are a couple of controls you can fiddle with (as it is currently programmed, these only take effect after the next song if one is already playing). "Keep on" determines the number of previous tracks to take into account in the generation of the playlist and "Drunk" specifies how much randomness to throw into the mix. Alternatively, you can create an MP3 mix of a musical journey of your choosing with

python Join_the_dots.py Pickles\mp3tovecs\mp3tovec.p --input tracks.txt mix.mp3 9

where "tracks.txt" is a text file containing a list of MP3 or M4A files and, here, 9 is the number of additional tracks you want to generate between each of these.

If you are interested in the data I used to train the neural network, feel free to drop me an email.

Generate .m3u playlist file

Optionally you can generate an .m3u file with relative path to export the playlist and play it on another device.

The playlist file uses relative paths. So if you specifiy --playlist as /home/user/playlists/playlist_outfile.m3u and one of its tracks is located at /home/user/music/some_awesome_music.mp3 the resulting playlist will write that track out as ../music/some_awesome_music.mp3.

Run with:

python Deej-A.I.py Pickles mp3tovec --playlist playlist_outfile.m3u --inputsong startingsong.mp3

It additionally takes optional parameters:

--nsongs  # Number of songs in the playlist
--noise   # Amount of noise in the playlist (default 0)
--lookback # Amount of lookback in the playlist (default 3)

deej-ai's People

Contributors

alfredjkwack avatar labachos avatar nickdurante avatar nnyj avatar teticio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deej-ai's Issues

Amazing results!

Quality of generated playlists is really great, thank you for your work!
Along the way, it allows to deduplicate the music library, since the same tracks follow each other)) I've been dreaming of doing something like this for a very long time!
Do you consider downloading texts and searching for the nearest ones not only by spectrogram, but also by "meaning" as the development of the project? Perhaps a linear combination of similarity in music and text...This could allow you to search for at least tracks in one language)

Unable to adjust sliders with a screenreader.

Hello, just found this project and set it up. However, when accessing the webpage to start, the sliders for Keep On and Drunk are not accessible to those who use a screenreader. I use nvda as my screenreader, and the only things that I can see are several clickable objects and the numbers for the start and end of the sliders, but no way to adjust them. When using object navigation, I see the NVDA says Diagram where I think the sliders should be.

suggestion: skip broken files

Often I get

Traceback (most recent call last):
  File "f:\Stuff\Programming\libs\deejAI.py", line 6, in <module>
    audio_encoder.encode(files)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\audiodiffusion\audio_encoder.py", line 89, in encode
    self.mel.load_audio(audio_file)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\diffusers\pipelines\audio_diffusion\mel.py", line 98, in load_audio
    self.audio, _ = librosa.load(audio_file, mono=True, sr=self.sr)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\librosa\util\decorators.py", line 88, in inner_f
    return f(*args, **kwargs)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\librosa\core\audio.py", line 218, in load
    y = resample(y, orig_sr=sr_native, target_sr=sr, res_type=res_type)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\librosa\util\decorators.py", line 88, in inner_f
    return f(*args, **kwargs)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\librosa\core\audio.py", line 686, in resample
    y_hat = resampy.resample(y, orig_sr, target_sr, filter=res_type, axis=-1)
  File "D:\Mambaforge\envs\audiodiffusion\lib\site-packages\resampy\core.py", line 117, in resample
    raise ValueError(
ValueError: Input signal length=0 is too small to resample from 44100->22050

and it stops the whole program
example audiofile:
100 gecs - Hand Crushed By A Mallet (Soup Remix).zip

the issue is that when librosa opens it it has shape 2,0

if anyone has the same issue (i have it with every 20th mp3 approximately)
go to D:\Mambaforge\envs\audiodiffusion\lib\site-packages\diffusers\pipelines\audio_diffusion\mel.py
search for def load_audio
and replace
if audio_file is not None:
self.audio, _ = librosa.load(audio_file, mono=True, sr=self.sr)

with
if audio_file is not None:
try:
self.audio, _ = librosa.load(audio_file, mono=True, sr=self.sr)
except:
try:
import madmom
self.audio, _ = madmom.io.audio.load_audio_file(audio_file, dtype=float, sample_rate=self.sr, num_channels=1)
self.audio=self.audio.T
except:
try:
import pedalboard.io
with pedalboard.io.AudioFile(audio_file).resampled_to(self.sr) as f:
self.audio = f.read(f.frames)
#samplerate = f.samplerate
except:
import soundfile
self.audio, _ = soundfile.read(audio_file, samplerate=self.sr, channels=1)
self.audio=self.audio.T

also install ffmpeg-python and pedalboard

Unable to install requirements on Windows

When trying to install requirements on Windows 10 via ' pip install -r requirements.txt' I receive the following error:

ERROR: Could not find a version that satisfies the requirement tensorflow==2.2.0 (from versions: 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0rc0, 2.6.0rc1, 2.6.0rc2, 2.6.0, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.7.0rc0, 2.7.0rc1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.8.0rc0, 2.8.0rc1, 2.8.0, 2.8.1, 2.8.2, 2.9.0rc0, 2.9.0rc1, 2.9.0rc2, 2.9.0, 2.9.1)
ERROR: No matching distribution found for tensorflow==2.2.0

I attempted to install a later version of tensorflow which requires later versions of other packages but run into many errors later on.

No module named 'audiodiffusion.audio_encoder'; 'audiodiffusion' is not a package

ModuleNotFoundError
No module named 'audiodiffusion.audio_encoder'; 'audiodiffusion' is not a package
AttributeError: partially initialized module 'audiodiffusion' has no attribute '__path__' (most likely due to a circular import)

During handling of the above exception, another exception occurred:

  File "F:\Stuff\Programming\libs\audiodiffusion.py", line 3, in <module>
    from audiodiffusion.audio_encoder import AudioEncoder
  File "F:\Stuff\Programming\libs\audiodiffusion.py", line 3, in <module>
    from audiodiffusion.audio_encoder import AudioEncoder
ModuleNotFoundError: No module named 'audiodiffusion.audio_encoder'; 'audiodiffusion' is not a package

KeyError generating mp3 mix or playlist

Hello! I've just discovered this and I'm trying it!
I set up an Ubuntu LXC container, installed all the things included the requirements.txt, and launched the scan process with success. Now I have my Picker directory with all the data.

python3 MP3ToVec.py Pickles mp3tovec --scan /home/ubuntu/deejai/ayj/

I'm using a small set of files (52 mp3) to test this. Then I created a tracks.txt file, containing just

'06 - Ella Fitzgerald - Cheek To Cheek.mp3'
'07 - Michael Buble - Come Fly With Me.mp3'
'08 - Paolo Nutini - Coming Up Easy.mp3'
'09 - Karen Souza - Creep.mp3'

or

'/home/ubuntu/deejai/ayj/06 - Ella Fitzgerald - Cheek To Cheek.mp3'
'/home/ubuntu/deejai/ayj/07 - Michael Buble - Come Fly With Me.mp3'
'/home/ubuntu/deejai/ayj/08 - Paolo Nutini - Coming Up Easy.mp3'
'/home/ubuntu/deejai/ayj/09 - Karen Souza - Creep.mp3'

But when I try

python3 Join_the_dots.py Pickles/mp3tovecs/mp3tovec.p --input tracks.txt mix.mp3 6

I always get the KeyError

Traceback (most recent call last):
  File "/home/ubuntu/deejai/Deej-AI/Join_the_dots.py", line 129, in <module>
    playlist = join_the_dots(input_tracks, n=n, noise=noise)
  File "/home/ubuntu/deejai/Deej-AI/Join_the_dots.py", line 67, in join_the_dots
    start_vec = mp3tovec[start]
KeyError: "'06 - Ella Fitzgerald - Cheek To Cheek.mp3'"

What am I doing wrong?

Trying to do python3 Deej-A.I.py Pickles mp3tovec or trying to create the playlist gives me this error:

Traceback (most recent call last):
  File "/home/ubuntu/deejai/Deej-AI/Deej-A.I.py", line 32, in <module>
    app = dash.Dash()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/dash/dash.py", line 236, in __init__
    self.server.before_first_request(self._setup_server)
AttributeError: 'Flask' object has no attribute 'before_first_request'. Did you mean: '_got_first_request'?

Just to add some more info.

Please add FLAC support

Hi there. Most of my songs are in flac format.
It'd be nice to have flac support.
Is this doable?

wrong m3u after second scan of a library

Hi , got a bug :
Generated database with command (20 of 20 has scanned)
python MP3ToVec.py Pickles mp3tovec --scan C:\mp3library
Than generated m3u with
python Deej-A.I.py Pickles mp3tovec --playlist C:\m3ufiles\000000018.m3u8 --inputsong C:\mp3library\66.mp3 --nsongs 3
Got correct m3u ( with similar songs)
Next added another song to C:\mp3library , and ran the command again
python MP3ToVec.py Pickles mp3tovec --scan C:\mp3library
New song added to database (1 of 1 has scanned)

When tried to get m3u again
python Deej-A.I.py Pickles mp3tovec --playlist C:\m3ufiles\000000018.m3u8 --inputsong C:\mp3library\66.mp3 --nsongs 3
got error :
C:\Deej-AI-master\Deej-A.I.py:186: RuntimeWarning: invalid value encountered in scalar divide
cos_proximity = np.dot(mp3_vec_i, mp3_vec_j) / (np.linalg.norm(mp3_vec_i) * np.linalg.norm(mp3_vec_j))
Got m3u generated , but songs in it not similar at all

In short - after adding new song to lib and additional scan , that leads to error (with wrong(not similar) m3u output)

Mp3ToVec Skips my MP3s

I can't seem to figure out why?

last 10 lines:

Skipping /Users/dariuspleasant/Documents/Music/Music 2/79rs Gang/Expect The Unexpected/07 79rs Gang and Lakou Mizik- Iko Kreyòl (79rs Version).mp3
100%|█████████████████████████████████████| 1362/1362 [00:20<00:00, 65.92file/s]
Creating MP3ToVecs for batch 1/1
Precalculating cosine distances
0vector [00:00, ?vector/s]
Calculating IDF weights
0vector [00:00, ?vector/s]
Calculating TF weights
0mp3 [00:00, ?mp3/s]


pip freeze

absl-py==0.13.0
astunparse==1.6.3
audioread==2.1.9
Brotli==1.0.9
cachetools==4.2.2
certifi==2021.5.30
charset-normalizer==2.0.3
click==8.0.1
dash==0.42.0
dash-core-components==0.47.0
dash-daq==0.1.4
dash-html-components==0.16.0
dash-renderer==0.23.0
dash-table==3.6.0
dataclasses==0.8
decorator==5.0.9
Flask==1.0.2
Flask-Compress==1.10.1
gast==0.3.3
google-auth==1.33.1
google-auth-oauthlib==0.4.4
google-pasta==0.2.0
grpcio==1.39.0
h5py==2.10.0
idna==3.2
importlib-metadata==4.6.1
itsdangerous==2.0.1
Jinja2==3.0.1
joblib==1.0.1
Keras==2.3.1
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
librosa==0.6.3
llvmlite==0.31.0
Markdown==3.3.4
MarkupSafe==2.0.1
mutagen==1.42.0
numba==0.48.0
numpy==1.16.3
oauthlib==3.1.1
opt-einsum==3.3.0
pandas==0.24.2
Pillow==8.3.1
plotly==5.1.0
protobuf==3.17.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
python-dateutil==2.8.2
pytz==2021.1
PyYAML==5.4.1
requests==2.26.0
requests-oauthlib==1.3.0
resampy==0.2.2
rsa==4.7.2
scikit-learn==0.24.2
scipy==1.4.1
six==1.16.0
spotipy==2.4.4
tenacity==8.0.1
tensorboard==2.2.2
tensorboard-plugin-wit==1.8.0
tensorflow==2.2.0
tensorflow-estimator==2.2.0
termcolor==1.1.0
threadpoolctl==2.2.0
tqdm==4.31.1
typing-extensions==3.10.0.0
urllib3==1.26.6
Werkzeug==2.0.1
wrapt==1.12.1
zipp==3.5.0

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!

Analyzing local music?

Hi!

I've been interested in this project for quite some time now, and I finally have enough free time to look into it properly.
It's great that this is so simple to use with Spotify, however, my use case is slightly different. I would like to integrate this with my Jellyfin server to get suggestions for my local music. As far as I can tell, you've split up the different processing steps in a way that should allow analyzing local tracks instead of downloaded previews, but I think I need to get my Jellyfin track IDs in there somehow, instead of the Spotify IDs. Exporting to m3u would work fine for the start.

I also found the "Try it out for yourself" section in the readme, and that seems to be mostly working, but I believe that is using outdated code, right? The rewritten version only works for Spotify I'd guess.

Could you give me pointers on how and where to ideally modify the code, if necessary? Or is there a way to hook into the process, e.g. by generating some supplementary csv files based on my Jellyfin library?
Thanks in advance!

m3u playlist generation: KeyError: 'file.mp3'

Hello, and thanks for the good work :)

I have an issue when I try to generate a playlist, I tried with various input songs and get the same error.

Thanks in advance :)

 python Deej-A.I.py Pickles mp3tovec --playlist playlist_outfile.m3u --inputsong max-sharks/Soul\ Edifice\ -\ National\ Insurrection.mp3
26 MP3s
Outfile playlist: playlist_outfile.m3u
Input song selected: max-sharks/Soul Edifice - National Insurrection.mp3
Requested None songs
Traceback (most recent call last):
  File "Deej-A.I.py", line 488, in <module>
    tracks = make_playlist([input_song], size=n_songs + 1, noise=noise, lookback=lookback)
  File "Deej-A.I.py", line 208, in make_playlist
    similar = most_similar(positive=playlist[-lookback:], topn=max_tries, noise=noise)
  File "Deej-A.I.py", line 179, in most_similar
    mp3_vec_i = np.sum([mp3tovec[i] for i in positive] + [-mp3tovec[i] for i in negative], axis=0)
  File "Deej-A.I.py", line 179, in <listcomp>
    mp3_vec_i = np.sum([mp3tovec[i] for i in positive] + [-mp3tovec[i] for i in negative], axis=0)
KeyError: 'max-sharks/Soul Edifice - National Insurrection.mp3'

Update Readme.md to include directions for Redirect URI?

Great App! I was trying to make it work with one of my Spotify playlists and was unable to understand how tokenization works with the redirect URI...could you add instructions to either the colab page or the readme.md? Thanks so much!

[Feature request] Ability to export .m3u playlist

Hi teticio,

I find your work really impressive, congrats on this great work!
Using it I though that the ability to export the generated playlist to a .m3u file would be a great feature to make the program more portable.
Have you had any thoughts on that?

Getting ValueError: Unknown loss function: cosine_proximity. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details. when trying to run

Not really sure what's up, I tried to run the code with the requirements (it couldn't find the right version of tensorflow so I just installed the latest one) and then this happens when I try to scan my music library.

C:\Users\Panda\Documents\Codestuffs\Deej-AI-master>python MP3ToVec.py Pickles mp3tovec --scan "E:\Panda\Music\iTunes\iTunes Media\Music"
2022-11-14 23:03:32.790183: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-11-14 23:03:32.790836: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Creating Track2Vec matrices
2022-11-14 23:03:35.199784: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library nvcuda.dll
2022-11-14 23:03:35.219181: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: NVIDIA GeForce RTX 3080 computeCapability: 8.6
coreClock: 1.785GHz coreCount: 70 deviceMemorySize: 12.00GiB deviceMemoryBandwidth: 849.46GiB/s
2022-11-14 23:03:35.219800: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-11-14 23:03:35.220358: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2022-11-14 23:03:35.220845: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2022-11-14 23:03:35.221412: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2022-11-14 23:03:35.222379: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2022-11-14 23:03:35.222909: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2022-11-14 23:03:35.223424: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2022-11-14 23:03:35.223939: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2022-11-14 23:03:35.224073: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1766] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2022-11-14 23:03:35.224545: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-11-14 23:03:35.225276: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-11-14 23:03:35.225335: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264]
Traceback (most recent call last):
File "C:\Users\Panda\Documents\Codestuffs\Deej-AI-master\MP3ToVec.py", line 42, in
model = load_model(model_file)
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\saving\save.py", line 201, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\saving\hdf5_format.py", line 198, in load_model_from_hdf5
model.compile(**saving_utils.compile_args_from_training_config(
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\saving\saving_utils.py", line 212, in compile_args_from_training_config
loss = _deserialize_nested_config(losses.deserialize, loss_config)
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\saving\saving_utils.py", line 253, in _deserialize_nested_config
return deserialize_fn(config)
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\losses.py", line 2020, in deserialize
return deserialize_keras_object(
File "C:\Users\Panda\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\utils\generic_utils.py", line 698, in deserialize_keras_object
raise ValueError(
ValueError: Unknown loss function: cosine_proximity. Please ensure this object is passed to the custom_objects argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

Suggestion for data source: lastfm or listenbrainz

Hi, really cool project!
I have 2 more suggestions for data sources to train the model on.
https://last.fm and https://listenbrainz.org/ allow users to track the songs they are listening to (and allow you to query that information). While you don't get playlists, the plays are tagged with a timestamp, so you could look for consecutive plays of songs and split e.g. when there is a break of more than 30min between songs.

Developer terms restrictions?

Hi,

Great work with this. I have been building a bit on the side of this for about a year on some ideas, but then I noticed the terms of service for development in Spotify API, do you have any better knowledge around this?
https://developer.spotify.com/terms#section-iv-restrictions

General restrictions.

Misuse of the Spotify Platform. Do not misuse the Spotify Platform, including by
    using the Spotify Platform or any Spotify Content to train a machine learning or AI model or otherwise ingesting Spotify Content into a machine learning or AI model;
  1. Governing Law

Notwithstanding any other provision in the Developer Agreement, this Appendix shall be governed by, and interpreted in accordance with, the laws of Sweden.

Cheers
dasbts

Skips all MP3s

I have ffmpeg, gstreamer, librosa, soundfile, audioread, yet none of my mp3s are processed.
Running Arch Linux, installed dependencies via pacman (some from AUR)

image

How do I get this working

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.