conda模式安装paddlepaddle2.4.2版本
一、下载anaconda 2022.10 window-x86-x64.exe
清华镜像源Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror,进去后根据自己的需要选择对应的版本下载
下载安装到磁盘空闲空间要大的D:\ProgramData\Anaconda3
设置Path
path+=
D:\ProgramData\Anaconda3
D:\ProgramData\Anaconda3\Scripts
D:\ProgramData\Anaconda3\Library\bin
D:\ProgramData\Anaconda3\Library\mingw-w64\bin
查看版本:
conda --version
conda 22.9.0
python
Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
二、国内镜像源配置
通过win+R输入cmd进入命令行,通过输入下面命令配置为清华源:
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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
三、conda模式 安装paddlepaddle-gpu==2.4.2 cuda10.2
conda install paddlepaddle-gpu==2.4.2 cudatoolkit=10.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge
四、vscode测试
# 查看 paddle能够调用 gpuimport paddle
paddle.fluid.is_compiled_with_cuda()
paddle.utils.run_check()'''
特别注意:
在vscode中使用创建的虚拟环境
选择python的解释器:在vscode中按住快捷键Ctrl+shift+P,输入Python然后执行如下图:
Python:Select Interpreter
select D:\ProgramData\Anaconda3\python.exe
'''
测试结果: 安装成功
PS E:\project\python>& D:/ProgramData/Anaconda3/python.exe e:/project/python/gpu-install.py
Running verify PaddlePaddle program ...
W0731 20:45:35.723439 3984 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 12.2, Runtime API Version: 10.2
W0731 20:45:35.740528 3984 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
PaddlePaddle works well on 1 GPU.
PaddlePaddle works well on 1 GPUs.
PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
五、用GPU测试手写数字识别模型情况
结论:GPU执行训练时间从702秒变成69秒,从11分钟变成1分钟
GPU测试结果:运行时间Cost time: 69.26997494697571
本次预测的数字是: 0
原CPU测试结果:#运行时间Cost time: 702.2813944816589
本次预测的数字是: 0
# 使用SGD优化器,learning_rate设置为0.01时loss下降明显最优 #cost time=705.9078650474548=11.75分钟#opt = paddle.optimizer.SGD(learning_rate=0.01, parameters=model.parameters()) #运行时间cost time: 705.9078650474548#opt = paddle.optimizer.SGD(learning_rate=0.001, parameters=model.parameters()) #运行时间Cost time: 705.5072021484375#opt = paddle.optimizer.SGD(learning_rate=0.0001, parameters=model.parameters()) #运行时间Cost time: 708.7056725025177#opt = paddle.optimizer.Momentum(learning_rate=0.01, momentum=0.9, parameters=model.parameters()) #运行时间Cost time: 707.7317929267883#opt = paddle.optimizer.Adagrad(learning_rate=0.01, parameters=model.parameters()) #运行时间Cost time: 756.807531118393
opt = paddle.optimizer.Adam(learning_rate=0.01, parameters=model.parameters())#运行时间Cost time: 702.2813944816589
PS E:\project\python>& D:/ProgramData/Anaconda3/python.exe e:/project/python/MNIST_Good.py
9.2.0
2.4.2
视觉相关数据集: ['DatasetFolder', 'ImageFolder', 'MNIST', 'FashionMNIST', 'Flowers', 'Cifar10', 'Cifar100', 'VOC2012']
自然语言相关数据集: []
数据处理方法: ['BaseTransform', 'Compose', 'Resize', 'RandomResizedCrop', 'CenterCrop', 'RandomHorizontalFlip', 'RandomVerticalFlip', 'Transpose', 'Normalize', 'BrightnessTransform', 'SaturationTransform', 'ContrastTransform', 'HueTransform', 'ColorJitter', 'RandomCrop', 'Pad', 'RandomAffine', 'RandomRotation', 'RandomPerspective', 'Grayscale', 'ToTensor', 'RandomErasing', 'to_tensor', 'hflip', 'vflip', 'resize', 'pad', 'affine', 'rotate', 'perspective', 'to_grayscale', 'crop', 'center_crop', 'adjust_brightness', 'adjust_contrast', 'adjust_hue', 'normalize', 'erase']
训练数据集数量: 60000
第一个图片为 (28, 28)[5]
W0731 20:48:01.011943 20788 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 12.2, Runtime API Version: 10.2
W0731 20:48:01.021474 20788 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
loading mnist dataset from ./work/mnist.json.gz ......
mnist dataset load done
训练数据集数量: 50000
epoch: 0, batch: 0, loss is: 2.6393485069274902
epoch: 0, batch: 200, loss is: 0.03634800389409065
epoch: 0, batch: 400, loss is: 0.06814056634902954
epoch: 1, batch: 0, loss is: 0.028553010895848274
epoch: 1, batch: 200, loss is: 0.044877491891384125
epoch: 1, batch: 400, loss is: 0.021085500717163086
epoch: 2, batch: 0, loss is: 0.09579199552536011
epoch: 2, batch: 200, loss is: 0.040042776614427567
epoch: 2, batch: 400, loss is: 0.04694807901978493
epoch: 3, batch: 0, loss is: 0.039875153452157974
epoch: 3, batch: 200, loss is: 0.012882424518465996
epoch: 3, batch: 400, loss is: 0.013728930614888668
epoch: 4, batch: 0, loss is: 0.004363641142845154
epoch: 8, batch: 0, loss is: 0.005882401950657368
epoch: 8, batch: 200, loss is: 0.06317561864852905
epoch: 8, batch: 400, loss is: 0.05743202567100525
epoch: 9, batch: 0, loss is: 0.014044929295778275
epoch: 9, batch: 200, loss is: 0.032656021416187286
epoch: 9, batch: 400, loss is: 0.002203206531703472
运行时间Cost time: 69.26997494697571
e:\project\python\MNIST_Good.py:247: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10(2023-07-01). Use Resampling.LANCZOS instead.
im = im.resize((28, 28), Image.LANCZOS)
本次预测的数字是: 0
PS E:\project\python>
—the—end—
版权归原作者 hsg77 所有, 如有侵权,请联系我们删除。