Anaconda + Tensorflow 环境搭建
1. Anaconda
1.1 Anaconda 常用命令
1 2
| conda --version conda update conda
|
1 2 3 4 5 6
| # 帮助命令 conda -h
# 更新所有包 conda update --all conda upgrade --all
|
1.2 Anaconda 管理环境
1
| conda create --name <env_name> <package_names>
|
如: conda create -n python3 python=3.5 numpy pandas
即创建一个名为“python3”的环境,环境中安装版本为3.5的python,同时也安装了numpy和pandas。
1 2 3 4 5
| conda info --envs
conda env list
source activate <env_name>
|
1 2 3 4 5
| conda create --name <new_env_name> --clone <copied_env_name>
conda remove --name <env_name> --all
|
1 2 3 4
| pip list / conda list
pip install <package_name>
|
2. Tensorflow
1
| conda install pandas xlrd
|
1 2
| conda install keras==2.2.4 pip install keras-bert
|
1 2
| conda install tensorflow=='1.11.0' conda install tensorflow-gpu=='1.11.0'
|
3. GPU
1 2 3 4 5 6 7 8 9 10 11
| nvidia-smi
+-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 6 7847 C python 11615MiB | | 7 6412 C python 4219MiB | | 8 36257 C .../anaconda2/envs/bert-serving/bin/python 11615MiB | | 9 17293 C /home/xxx/.conda/envs/aspect/bin/python 11613MiB | +-----------------------------------------------------------------------------+
|
解决 cuda10 因为显卡驱动不支持的
1
| conda install cudatoolkit=9.0
|
用如下代码可检测tensorflow的能使用设备情况:
1 2
| from tensorflow.python.client import device_lib print(device_lib.list_local_devices())
|
4. CPU
Keras以及Tensorflow强制使用CPU
使用CUDA_VISIBLE_DEVICES命令行参数,代码如下:
1
| CUDA_VISIBLE_DEVICES="" python3 train.py
|
Reference
Good!
Checking if Disqus is accessible...