Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. # TensorFlow/PyTorch + GPU + Docker
  2.  
  3. The steps described here was made and tested in **Ubuntu 18.04 x64**, and it's main purpose is make easy to prepare environment from scratch to play with Deep Learning on TensorFlow/PyTorch.
  4.  
  5. ## Steps to prepare environment
  6.  
  7. 1. Update system
  8.  
  9. `$> sudo apt-get -y update`
  10.  
  11. 2. Install requirements
  12.  
  13. `$> sudo apt install -y python3-pip curl`
  14.  
  15. 3. Install getgist
  16.  
  17. `$> pip3 install getgist`
  18. > If you had any issue with getgist REBOOT your system
  19.  
  20. 4. Install Miniconda
  21.  
  22. `$> getgist rodrigocmoraes install-miniconda.sh`
  23.  
  24. `$> bash install-miniconda.sh`
  25.  
  26. > Execute the steps below manually when necessary:
  27. > * Enter
  28. > * yes
  29. > * Enter
  30. > * yes
  31.  
  32. > After installation execute command below:
  33.  
  34. `$> source ~/.`
  35.  
  36. 5. Install NVidia Driver
  37.  
  38. `$> getgist rodrigocmoraes install-nvidia-driver.sh`
  39.  
  40. `$> bash install-nvidia-driver.sh`
  41.  
  42. > Execute the steps below manually when necessary;
  43. > * Enter
  44.  
  45. 6. Install Docker/Docker Compose
  46.  
  47. `$> getgist rodrigocmoraes install-docker.sh`
  48.  
  49. `$> bash install-docker.sh`
  50.  
  51. `$> sudo usermod -aG docker $USER`
  52.  
  53. `$> sudo reboot`
  54.  
  55.  
  56. 7. Install NVidia Docker
  57.  
  58. `$> getgist rodrigocmoraes install-nvidia-docker.sh`
  59.  
  60. `$> bash install-nvidia-docker.sh`
  61.  
  62. `$> sudo reboot`
  63.  
  64.  
  65. 8. Create
  66.  
  67. 8.1. TensorFlow - GPU:
  68.  
  69. `$> getgist rodrigocmoraes spec-file-tensorflow-gpu.txt`
  70.  
  71. `$> conda create --name tensorflow-gpu --file spec-file-tensorflow-gpu.txt python=3.6.8`
  72.  
  73. `$> conda activate tensorflow-gpu`
  74.  
  75. `$> pip install opencv-python`
  76.  
  77. `$> conda deactivate`
  78.  
  79. 8.2. PyTorch - GPU:
  80.  
  81. `$> getgist rodrigocmoraes spec-file-pytorch-gpu.txt`
  82.  
  83. `$> conda create --name pytorch-gpu --file spec-file-pytorch-gpu.txt python=3.6.8`
  84.  
  85. `$> conda activate pytorch-gpu`
  86.  
  87. `$> pip install opencv-python future`
  88.  
  89. `$> conda deactivate`
  90.  
  91. ## Test environments:
  92.  
  93. * TensorFlow - GPU:
  94.  
  95. ```python
  96. from tensorflow.python.client import device_lib
  97. def get_available_gpus():
  98. local_device_protos = device_lib.list_local_devices()
  99. return [x.name for x in local_device_protos if x.device_type == 'GPU']
  100. print(get_available_gpus())
  101. ```
  102.  
  103. > Expected result:
  104. `>>> ['/device:GPU:0']`
  105.  
  106.  
  107. * PyTorch - GPU:
  108.  
  109. ```python
  110. import torch
  111. id = torch.cura.current_device()
  112. print(id)
  113. print(torch.cuda.get_device_name(id))
  114. ```
  115.  
  116. ## Most used *conda* commands:
  117.  
  118. * List conda existing conda environment:
  119.  
  120. `$> conda env list`
  121.  
  122. * Activate conda environment:
  123.  
  124. `$> conda activate ENVIRONMENT_NAME`
  125.  
  126. * Deactivate conda environment:
  127.  
  128. `$> conda deactivate`
  129.  
  130. * Install packages into conda environment:
  131.  
  132. `$> conda install --name ENVIRONMENT_NAME PACKAGE[==X.YY.ZZ]`
  133.  
  134. or
  135.  
  136. `$> conda activate ENVIRONMENT_NAME`
  137.  
  138. `$> conda install PACKAGE[==X.YY.ZZ]`
  139.  
  140. or from *spec-file.txt*
  141.  
  142. `$> conda install --name ENVIRONMENT_NAME PACKAGE[==X.YY.ZZ] --file spec-file.txt`
  143.  
  144. or from *requirements.txt*
  145.  
  146. `$> while read requirement; do conda install --yes $requirement; done < requirements.txt`
  147.  
  148. * Export environment specification:
  149.  
  150. * From **conda** package manager:
  151.  
  152. `$> conda list --explicit > spec-file-${CONDA_DEFAULT_ENV}.txt`
  153.  
  154. * From **pip** package manager:
  155.  
  156. `$> pip freeze > requirements-${CONDA_DEFAULT_ENV}.txt`
  157.  
  158. * Clone environment:
  159.  
  160. `$> conda create --name NEW_ENV_NAME --clone ENV_THAT_WILL_BE_CLONNED`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement