kahst / AcousticEventDetection

Source code complementing our paper for acoustic event classification using convolutional neural networks.
MIT License
65 stars 28 forks source link

Dependencies #3

Open Lelo123 opened 6 years ago

Lelo123 commented 6 years ago

Good afternoon.

Can you specify the different dependencies that you used for this code? The CUDA version, CuDNN, python libraries, theano, etc?

I'm having a lot of problems using your code.

Thanks.

kahst commented 6 years ago

The versions that you need for your machine differ, depending on OS and GPU. I did the following, the last time I installed all dependencies for my repositories using Ubuntu 16.04:

CUDA

Download CUDA:

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork

Install CUDA:

sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

Add to path:

export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

cuDNN

Download cuDNN (you need to be registered):

http://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

Installing from a Tar File:

Navigate to your directory containing the cuDNN Tar file. Unzip the cuDNN package.

$ tar -xzvf cudnn-9.0-linux-x64-v7.tgz

Copy the following files into the CUDA Toolkit directory.

$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Theano

Prerequisites:

sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install numpy
sudo pip install scipy
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install cmake
sudo pip install cython

Install gpuarray:

http://deeplearning.net/software/libgpuarray/installation.html

git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray
mkdir Build
cd Build
cmake .. -DCMAKE_BUILD_TYPE=Release # or Debug if you are investigating a crash
make
make install
cd ..

python setup.py build
sudo python setup.py install

python setup.py build_ext -L $MY_PREFIX/lib -I $MY_PREFIX/include
sudo ldconfig

Install Theano:

git clone git://github.com/Theano/Theano.git
cd Theano
sudo pip install -e .

.theanorc

Adjust .theanorc content:

[global]
device=cuda
floatX=float32
optimizer_excluding=low_memory

[mode]=FAST_RUN

[dnn.conv]
algo_bwd_filter=deterministic
algo_bwd_data=deterministic

[gpuarray]
preallocate=0

Lasagne

Last but not least, install Lasagne

sudo pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt
sudo pip install https://github.com/Lasagne/Lasagne/archive/master.zip

You should be able to install all other Python packages needed for the repository without any trouble.

I hope this helps.

Lelo123 commented 6 years ago

Thank you very much! I'll give it a try.

Wild1234 commented 6 years ago

Did you tested your Neural Network on Ubuntu 16.04 and did it worked @kahst?

kahst commented 6 years ago

Yes and no. I'm still using some of the code in my current projects which all run on Ubuntu 16.04. However, you might not be able to use the trained model provided via download - some changes in Theano and Lasagne might prevent that from working. Otherwise, it should run properly - give me a hint if you run into any trouble.

Lelo123 commented 6 years ago

(AcousticEvent) bfe2brg@PT-IW002:~/AcousticEventDetection$ python2 AED_test.py --filenames 'dataset/schreien_scream.wav' --modelname 'AED_Example_Run_model.pkl' --overlap 4 --results 5 --confidence 0.01 HANDLING IMPORTS... WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions. ...DONE! IMPORTING MODEL... Traceback (most recent call last): File "AED_test.py", line 156, in NET, CLASSES, IM_SIZE, IM_DIM = loadModel(TRAINED_MODEL) File "AED_test.py", line 57, in loadModel data = pickle.load(f) File "/usr/lib/python2.7/pickle.py", line 1384, in load return Unpickler(file).load() File "/usr/lib/python2.7/pickle.py", line 864, in load dispatchkey File "/usr/lib/python2.7/pickle.py", line 1139, in load_reduce value = func(*args) File "/home/bfe2brg/.local/lib/python2.7/site-packages/theano/gpuarray/type.py", line 868, in GpuArray_unpickler raise ImportError("pygpu not found. Cannot unpickle GpuArray") ImportError: pygpu not found. Cannot unpickle GpuArray

Can you help pls?

kahst commented 6 years ago

It seems to me that you are trying to run the model in CPU mode. You need to get gpuarray running before you can load a pickled model. As I mentioned above, even if you have gpuarray installed, you might not be able run the script with the pre-trained model due to changes in Theano and Lasagne. Still, your error messages implies that you are missing gpuarray.

Lelo123 commented 6 years ago

(NAME) bfe2brg@PT-IW002:~/AcousticEventDetection$ python2 AED_test.py --filenames 'dataset/schreien_scream.wav' --modelname 'AED_Example_Run_model.pkl' --overlap 4 --results 5 --confidence 0.01 HANDLING IMPORTS... ...DONE! IMPORTING MODEL... Traceback (most recent call last): File "AED_test.py", line 156, in NET, CLASSES, IM_SIZE, IM_DIM = loadModel(TRAINED_MODEL) File "AED_test.py", line 57, in loadModel data = pickle.load(f) File "/opt/ivs/anaconda/envs/NAME/lib/python2.7/pickle.py", line 1384, in load return Unpickler(file).load() File "/opt/ivs/anaconda/envs/NAME/lib/python2.7/pickle.py", line 864, in load dispatchkey File "/opt/ivs/anaconda/envs/NAME/lib/python2.7/pickle.py", line 1139, in load_reduce value = func(*args) File "/opt/ivs/anaconda/envs/NAME/lib/python2.7/site-packages/theano/gpuarray/type.py", line 865, in GpuArray_unpickler ctx = get_context(ctx_name) File "/opt/ivs/anaconda/envs/NAME/lib/python2.7/site-packages/theano/gpuarray/type.py", line 104, in get_context raise ContextNotDefined("context name %s not defined" % (name,)) theano.gpuarray.type.ContextNotDefined: context name None not defined

I've been able to solve that problem before...The problem is more directed for here now

kahst commented 6 years ago

This looks like gpuarray can't access your GPU which might have something to do with drivers&CUDA.

carstenschwede commented 6 years ago

@kahst Could you add the specific version requirements of the following libraries:

Currently git clone git://github.com/Theano/Theano.gitwill install Theano 1.0.1, but later on sudo pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt will install Theano 0.8.2.

Libgpuarray seems to work better with current versions of Theano (~1.0) while Lasagne seems to expect an older one (~0.8.2).

The installation hints you added above unfortunately do not result in a working environment, presumably due to these conflicting Theano requirements.

Currently Lasagne complains about Theano being too new ("missing downsample") and libgpuarray complains about Theano being too old ("major api mismatch between theano and pygpu").

kahst commented 6 years ago

@carstenschwede you are right, installing Theano from git results in version 1.0.1. Using pip show pygpu tells me I'm using version 0.7.5 and pip show lasagne says version 0.2.dev1.

The change of the requirements.txt in the Lasagne repo is 4 month old, older than the install I'm using. I guess this was already the case when I wrote the instructions and should work.

I'm sorry that I'm not of much help here, but maybe this is an issue for Lasagne, Jan usually responses very quickly.

carstenschwede commented 6 years ago

@kahst Thanks for the fast reply. Which Theano version are you using? These are my results:

Theano@1.0.1, Lasagne@0.2.dev1 and pygpu@0.7.5 results in the following error at lasagne/layers/conv.py:

AttributeError: 'Conv2DLayer' object has no attribute 'num_groups'


Theano@0.8.2, Lasagne@0.2.dev1 and pygpu@0.7.5 results in the following error at gpuarray/__init__.py:

Runtimerror: ('Wrong major API version for gpuarray:', 2, 'Make sure Theano and libgpuarray/pygpu are in sync.')

kahst commented 6 years ago

Ah, now I know what's going on: The newest version of Lasagne supports grouped convolutions. In that version, all Conv2DLayers have an additional argument named "num_groups". Unfortunately, the snapshot model provided as download contains pickled Conv2DLayer that are outdated.

The test script won't run because of that, you need to train your own net and save that snapshot, before you can actually test on unseen audio files. I'm sorry - for now, that seems to be the only solution.