window下GPU版Pytroch(1.8.0)和Tensoflow(2.5.0)安装过程简记(python 3.8)

GPU版本的两个使用环境,分别可以在Pycharm中切换使用。啥时候不用这么费劲搞环境。。。

一:PYTORCH1.8.0 环境python 3.8 
新建环境conda create -n my_python_env python=3.8
# To activate this environment, use
#
#     $ conda activate my_python_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate
activate my_python_env
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge


安装PYTROCH
安装D:\BaiduNetdiskDownload cuda11.1
conda create -n my_python_env python=3.8 
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit==11.0 -c pytorch


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes


activate my_python_env
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
安装pycharm 设置编译器


然后输入命令验证pytorch是否安装成功:
import torch 
print(torch.__version__)
接下来再验证pytorch调用cuda是否正确。输入命令:
print(torch.cuda.is_available())

显示:C:\Users\newy\anaconda3\envs\my_python_env\python.exe C:/Users/newy/PycharmProjects/pythonProject/main.py
1.8.0
True

Process finished with exit code 0


二:tensorflow2.5.0 (内含keras)
conda create -n tf-gpu python=3.8
#
# To activate this environment, use
#
#     $ conda activate tf-gpu
#
# To deactivate an active environment, use
#
#     $ conda deactivate

conda install tensorflow-gpu==2.5.0

pycharm修改setting编译器 选择tf-gpu
tensorflow2.5.0 包含keras
测试GPU使用
方法1
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
方法2
import tensorflow as tf
tf.config.list_physical_devices('GPU')

你可能感兴趣的:(机器学习,python,深度学习,pytorch,tensorflow)