facebookresearch / audiocraft

Audiocraft is a library for audio processing and generation with deep learning. It features the state-of-the-art EnCodec audio compressor / tokenizer, along with MusicGen, a simple and controllable music generation LM with textual and melodic conditioning.
MIT License
20.15k stars 2.01k forks source link

Cannot import MAGNeT from audiocraft.models #439

Open adityarajsahu opened 3 months ago

adityarajsahu commented 3 months ago

I tried getting the inference using this code snippet from the MAGNeT small model ` import torchaudio from audiocraft.models import MAGNeT from audiocraft.data.audio import audio_write

model = MAGNeT.get_pretrained('facebook/magnet-small-10secs') descriptions = ['disco beat', 'energetic EDM', 'funky groove'] wav = model.generate(descriptions) # generates 3 samples.

for idx, one_wav in enumerate(wav):

Will save under {idx}.wav, with loudness normalization at -14 db LUFS.

audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)

`

But, I am getting the following error ImportError: cannot import name 'MAGNeT' from 'audiocraft.models' (/usr/local/lib/python3.10/dist-packages/audiocraft/models/__init__.py) The MAGNeT model is present inside the audiocraft/models directory. I have no idea why it is not getting imported. How to resolve this error?

CosmosQiu commented 3 months ago

I tried getting the inference using this code snippet from the MAGNeT small model ` import torchaudio from audiocraft.models import MAGNeT from audiocraft.data.audio import audio_write

model = MAGNeT.get_pretrained('facebook/magnet-small-10secs') descriptions = ['disco beat', 'energetic EDM', 'funky groove'] wav = model.generate(descriptions) # generates 3 samples.

for idx, one_wav in enumerate(wav): # Will save under {idx}.wav, with loudness normalization at -14 db LUFS. audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True) `

But, I am getting the following error ImportError: cannot import name 'MAGNeT' from 'audiocraft.models' (/usr/local/lib/python3.10/dist-packages/audiocraft/models/__init__.py) The MAGNeT model is present inside the audiocraft/models directory. I have no idea why it is not getting imported. How to resolve this error?

Try to install audiocraft with: python -m pip install -e . # or if you cloned the repo locally (mandatory if you want to train).

It works out for me