-
Notifications
You must be signed in to change notification settings - Fork 0
Python envs for ML(TensorFlow and PyTorch)
Kewei Yan edited this page Mar 13, 2023
·
17 revisions
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
Use source ~/.bashrc
to refresh/restart terminal before using conda
(base)conda create -n py39 python=3.9
(base)conda activate py39
(py39)
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/' > $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
(py39)conda install -c conda-forge cudatoolkit=11.3 cudnn=8.1
(py39)pip install opencv-python
(py39)pip install tensorflow==2.11.*
Check if it is cuda enabled
(py39)python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
- If the code is implemented by Tensorflow1, then change
import tensorflow as tf
toimport tensorflow.compat.v1 as tf
- If
slim
is not working, then packagetf_slim
is needed, also, in the code, replaceslim = tf.contrib.slim
byimport tf_slim as slim
- If
libnvinfer.so.7
/libnvinfer_plugin.so.7
symbol not found is reported, then download the packagetensorRT
to getlibnvinfer.so.8
/libnvinfer_plugin.so.8
and create the soft-link oflibnvinfer.so.7
/libnvinfer_plugin.so.7
in pathenv/py39/lib/
- If
libtinfo.so.6
contains no version information of vim, bash, etc. create a soft-link of/lib/x86_64-linux-gnu/libtinfo.so.6
in pathenv/py39/lib/
- If
ValueError: Memory growth cannot differ between GPU devices
is reported, please insert the following lines:
gpus = tf.config.list_physical_devices('GPU') # find this line
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
(py39)pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
Check if it is cuda enabled
(py39)python -c "import torch; print(torch.cuda.is_available())"
- If
cudaGetStatusString
symbol not found is reported, then there could be something wrong withtorch
installation, considering using the line above instead of the namepytorch
only inrequirements.txt
- If
libtinfo.so.6
contains no version information of vim, bash, etc. create a soft-link of/lib/x86_64-linux-gnu/libtinfo.so.6
in pathenv/py39/lib/
One possible combination
Ubuntu 20.04
python 3.9
cudadriver 525.x(up to cuda 12.0)
cudatookit 11.3
cuDNN 8.1
opencv 4.6
tensorflow 2.11
pytorch 1.12.1