1、conda常用命令

命令 含义
conda list 查看当前环境安装的库
conda --V/version 查看 conda 版本
nvcc --V 查看GPU版本
python -V 查看 python 版本
conda info --env 查看已存在的虚拟环境
conda create -n xxxx python=3.6 创建python3.5的xxxx虚拟环境
conda create -n [虚拟环境名] --clone [要克隆的环境名] 克隆一个虚拟环境
conda activate xxxx 开启xxxx环境
conda deactivate 关闭环境
conda remove -n xxxx --all 删除xxxx虚拟环境
conda list -n xxx 指定查看 xxx 虚拟环境下安装的package
conda install xxx 安装 xxx 文件包
conda update xxx 更新 xxx 文件包
conda uninstall xxx 卸载 xxx 文件包
conda -h 查询conda的命令使用
jupyter notebook 打开 jupyter notebook
conda/pip install 目录/离线包名 安装 离线包

2、修改 anaconda 包管理镜像为国内源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ //添加清华源url

conda config --set show_channel_urls yes

conda config --remove-key channels // conda换回默认源

3、查看电脑计算方式CPU/GPU

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

一般存在名称:

/cpu:0 //机器的CPU
/gpu:0 //机器的第一个GPU,如果有的话
/gpu:1 // 机器的第二个GPU,…

4、查看电脑存在的处理器信息

import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"

if __name__ == "__main__":
print(device_lib.list_local_devices())

5、指定CPU或GPU进行计算

with tf.Session() as sess:
    with tf.device('/gpu:1'):
    	具体操作.......

或者在 程序开头

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'         # 使用 GPU 0
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐