# Easiest Cuda, cuDNN installation tutorial for Deep learning(Keras/TensorFlow)
## Nvidia Drivers
$sudo add-apt-repository ppa:graphics-drivers
$sudo apt-get update
then intsall the driver in Ubuntu settings -> Software and update-> Additional driver.
## Cuda
[CUDA 9 DOWNLOAD Link](https://developer.nvidia.com/cuda-90-download-archive?target_os=Linux) (Recommend)
1. choose the OSversion and click **deb(network)**
2. then run the instructions below
$ sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-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=9.0.176-1
`cuda=9.0.176-1` need to be corrsponded the downloaded deb file
`cuda-repo-ubuntu1604_9.0.176-1_amd64.deb`.
<font size=3 color=red>DO NOT USE</font> `sudo apt-get install cuda`, it maybe install other version of cuda.
3. edit `~/.bashrc` and add the text below
```console
#CUDA settings
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
```
## cuDNN
[cuDNN DOWNLOAD Link](https://developer.nvidia.com/rdp/form/cudnn-download-survey)
Download the cudnn with corresponding <font size=3 color=red>cuda version supported!</font>
* For example if you downloaded CUDA 9.0, then click
Download cuDNN v7.3.1 (Sept 28, 2018), for CUDA 9.0
1. sign in and download the 3 files
* cuDNN vx.x.x Runtime Library for Ubuntuxx.xx (Deb)
* cuDNN vx.x.x Developer Library for Ubuntuxx.xx (Deb)
* cuDNN vx.x.x Code Samples and User Guide for Ubuntuxx.xx (Deb)
2. run the instructions below
$ sudo dpkg -i libcudnnx_x.x.x.xx-x+cudax.x_amd64.deb
$ sudo dpkg -i libcudnnx-dev_x.x.x.xx-x+cudax.x_amd64.deb
$ sudo dpkg -i libcudnnx-doc_x.x.x.xx-x+cudax.x_amd64.deb
## Python installations
#### Anaconda [Download](https://www.anaconda.com/download/#linux) (Recommend)
1. install Python 3.6 is recommend
$ bash ~/Downloads/Anaconda-versionsxxxx-Linux-x86_64.sh
$ conda install python=3.6
2. create a enviroment..
$ conda create --name my-env python=3.6
3. activate the enviroment
$ conda activate my-env
4. install Tensorflow
$ pip install tensorflow-gpu
or
$ pip install tensorflow
5. install Keras
$ pip install keras
5. edit `~/.bashrc` and add this(optional)
```console
alias foo='conda activate my-env'
```
4. test if it work
* For tensorflow
```python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print (sess.run(hello))
```
* For Keras
```python
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout
def model(input_size=50):
model = Sequential()
model.add(Dense(50, input_dim=input_size, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(40, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(2,activation='linear'))
model.add(Dense(1))
# Compile model
model.compile(loss='mse', optimizer='adam')
return model
model = model(50)
print(model.summary())
```