当前位置: 首页 > news >正文

自己做营销网站wordpress主题qux_v7.1

自己做营销网站,wordpress主题qux_v7.1,三只松鼠口碑营销案例,wordpress如何做首页mac本地采用GPU启动keras运算 一、问题背景二、技术背景三、实验验证本机配置安装PlaidML安装plaidml-keras配置默认显卡 运行采用 CPU运算的代码step1 先导入keras包#xff0c;导入数据cifar10#xff0c;这里可能涉及外网下载#xff0c;有问题可以参考[keras使用基础问题… mac本地采用GPU启动keras运算 一、问题背景二、技术背景三、实验验证本机配置安装PlaidML安装plaidml-keras配置默认显卡 运行采用 CPU运算的代码step1 先导入keras包导入数据cifar10这里可能涉及外网下载有问题可以参考[keras使用基础问题](https://editor.csdn.net/md/?articleId140331142)step2 导入计算模型如果本地不存在该模型数据会自动进行下载有问题可以参考[keras使用基础问题](https://editor.csdn.net/md/?articleId140331142)step3 模型编译step4 进行一次预测step5 进行10次预测 运行采用 GPU运算的代码采用显卡metal_intel(r)_uhd_graphics_630.0step0 通过plaidml导入keras之后再做keras相关操作step1 先导入keras包导入数据cifar10step2 导入计算模型如果本地不存在该模型数据会自动进行下载step3 模型编译step4 进行一次预测step5 进行10次预测 采用显卡metal_amd_radeon_pro_5300m.0step0 通过plaidml导入keras之后再做keras相关操作step1 先导入keras包导入数据cifar10step2 导入计算模型如果本地不存在该模型数据会自动进行下载step3 模型编译step4 进行一次预测step5 进行10次预测 四、评估讨论 一、问题背景 从上一篇文章中我们已经发现在大模型的运算中采用cpu进行运算时对于cpu的使用消耗很大。因此我们这里会想到如果机器中有GPU显卡如何能够发挥显卡在向量运算中的优势将机器学习相关的运算做的又快又好。 二、技术背景 我们知道当前主流的支持机器学习比较好的显卡为 Nvida系列的显卡俗称 N卡但是在mac机器上通常集成的都是 AMD系列的显卡。两种不同的硬件指令集的差异导致上层需要有不同的实现技术。 但是在 AMD显卡中有一种PlaidML的技术通过该插件可以封装不同显卡的差异。 PlaidML项目地址https://github.com/plaidml/plaidml 目前 PlaidML 已经支持 Keras、ONNX 和 nGraph 等工具直接用 Keras 建个模MacBook 轻轻松松调用 GPU。 通过这款名为 PlaidML 的工具不论英伟达、AMD 还是英特尔显卡都可以轻松搞定深度学习训练了。 参考Mac使用PlaidML加速强化学习训练 三、实验验证 本次操作对于一个常规的keras的算法分别在cpu和 gpu下进行多轮计算统计耗时。进行对比统计。 本机配置 本次采用的mac机器的软件、硬件参数如下 安装PlaidML 由于安装依赖包的过程需要有命令交互因此安装plaidML包操作在命令行进行代码执行在 jupyter中进行。 由于采用虚拟环境时会jupyter会有需要创建 kernal的技术点因此这里建议暂时直接用原python环境进行验证。了解jupyter在虚拟环境的配置特点的同学可以尝试在虚拟环境中操作。 安装plaidml-keras pip3 install plaidml-keras笔者在采用命令 pip3 install plaidml-keras 安装最新版本plaidml-keras为0.7.0后在执行初始化操作时遇到bug后续降为0.6.4执行正常。但是后续再次安装为 0.7.0又正常了。 plaidml in github 配置默认显卡 在命令行执行 plaidml-setup交互内容如下 (venv) tsingjtsingjdeMacBook-Pro-2 ~ # plaidml-setupPlaidML Setup (0.6.4)Thanks for using PlaidML!Some Notes:* Bugs and other issues: https://github.com/plaidml/plaidml* Questions: https://stackoverflow.com/questions/tagged/plaidml* Say hello: https://groups.google.com/forum/#!forum/plaidml-dev* PlaidML is licensed under the Apache License 2.0Default Config Devices:metal_intel(r)_uhd_graphics_630.0 : Intel(R) UHD Graphics 630 (Metal)metal_amd_radeon_pro_5300m.0 : AMD Radeon Pro 5300M (Metal)Experimental Config Devices:llvm_cpu.0 : CPU (LLVM)metal_intel(r)_uhd_graphics_630.0 : Intel(R) UHD Graphics 630 (Metal)opencl_amd_radeon_pro_5300m_compute_engine.0 : AMD AMD Radeon Pro 5300M Compute Engine (OpenCL)opencl_cpu.0 : Intel CPU (OpenCL)opencl_intel_uhd_graphics_630.0 : Intel Inc. Intel(R) UHD Graphics 630 (OpenCL)metal_amd_radeon_pro_5300m.0 : AMD Radeon Pro 5300M (Metal)Using experimental devices can cause poor performance, crashes, and other nastiness.Enable experimental device support? (y,n)[n]:列举现实当前可以支持的显卡列表选择默认支持支持的2个显卡还是试验阶段所有支持的6 种硬件。 可以看到默认支持的 2 个显卡即最初截图中现实的两个显卡。为了测试稳定起见这里先选择N回车。 Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS). Please choose a default device:1 : metal_intel(r)_uhd_graphics_630.02 : metal_amd_radeon_pro_5300m.0Default device? (1,2)[1]:1Selected device:metal_intel(r)_uhd_graphics_630.0对于默认选择的设置设置一个默认设备这里我们先将metal_intel®_uhd_graphics_630.0设置为默认设备当然这个设备其实性能比较差后续我们会再将metal_amd_radeon_pro_5300m.0设置为默认设备进行对比。 写入 1 之后回车。 Almost done. Multiplying some matrices... Tile code:function (B[X,Z], C[Z,Y]) - (A) { A[x,y : X,Y] (B[x,z] * C[z,y]); } Whew. That worked.Save settings to /Users/tsingj/.plaidml? (y,n)[y]:y Success!回车将配置信息写入默认配置文件中完成配置。 运行采用 CPU运算的代码 本节中采用jupyter进行一个简单算法代码的运行统计其时间。 step1 先导入keras包导入数据cifar10这里可能涉及外网下载有问题可以参考keras使用基础问题 #!/usr/bin/env python import numpy as np import os import time import keras import keras.applications as kapp from keras.datasets import cifar10 (x_train, y_train_cats), (x_test, y_test_cats) cifar10.load_data() batch_size 8 x_train x_train[:batch_size] x_train np.repeat(np.repeat(x_train, 7, axis1), 7, axis2)注意这里默认的keral的运算后端应该是采用了tenserflow查看输出 2024-07-11 14:36:02.753107: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. step2 导入计算模型如果本地不存在该模型数据会自动进行下载有问题可以参考keras使用基础问题 model kapp.VGG19()step3 模型编译 model.compile(optimizersgd, losscategorical_crossentropy,metrics[accuracy])step4 进行一次预测 print(Running initial batch (compiling tile program)) y model.predict(xx_train, batch_sizebatch_size)Running initial batch (compiling tile program) 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 1s/step step5 进行10次预测 # Now start the clock and run 10 batchesprint(Timing inference...) start time.time() for i in range(10):y model.predict(xx_train, batch_sizebatch_size)print(Ran in {} seconds.format(time.time() - start))1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 891ms/step Ran in 0.9295139312744141 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 923ms/step Ran in 1.8894760608673096 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 893ms/step Ran in 2.818492889404297 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 932ms/step Ran in 3.7831668853759766 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 892ms/step Ran in 4.71358585357666 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 860ms/step Ran in 5.609835863113403 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 878ms/step Ran in 6.5182459354400635 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 871ms/step Ran in 7.423128128051758 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 896ms/step Ran in 8.352543830871582 seconds 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 902ms/step Ran in 9.288795948028564 seconds 运行采用 GPU运算的代码 采用显卡metal_intel®_uhd_graphics_630.0 step0 通过plaidml导入keras之后再做keras相关操作 # Importing PlaidML. Make sure you follow this order import plaidml.keras plaidml.keras.install_backend() import os os.environ[KERAS_BACKEND] plaidml.keras.backend注 1、在采用plaidml0.7.0 版本时plaidml.keras.install_backend()操作会发生报错 2、这步操作会通过plaidml导入keras将后台运算引擎设置为plaidml而不再采用tenserflow step1 先导入keras包导入数据cifar10 #!/usr/bin/env python import numpy as np import os import time import keras import keras.applications as kapp from keras.datasets import cifar10 (x_train, y_train_cats), (x_test, y_test_cats) cifar10.load_data() batch_size 8 x_train x_train[:batch_size] x_train np.repeat(np.repeat(x_train, 7, axis1), 7, axis2)step2 导入计算模型如果本地不存在该模型数据会自动进行下载 model kapp.VGG19()首次运行输出显卡信息 INFO:plaidml:Opening device “metal_intel®_uhd_graphics_630.0” step3 模型编译 model.compile(optimizersgd, losscategorical_crossentropy,metrics[accuracy])step4 进行一次预测 print(Running initial batch (compiling tile program)) y model.predict(xx_train, batch_sizebatch_size)Running initial batch (compiling tile program) 由于输出较快内容打印只有一行。 step5 进行10次预测 # Now start the clock and run 10 batchesprint(Timing inference...) start time.time() for i in range(10):y model.predict(xx_train, batch_sizebatch_size)print(Ran in {} seconds.format(time.time() - start))Ran in 4.241918087005615 seconds Ran in 8.452141046524048 seconds Ran in 12.665411949157715 seconds Ran in 16.849968910217285 seconds Ran in 21.025720834732056 seconds Ran in 25.212764024734497 seconds Ran in 29.405478954315186 seconds Ran in 33.594977140426636 seconds Ran in 37.7886438369751 seconds Ran in 41.98136305809021 seconds 采用显卡metal_amd_radeon_pro_5300m.0 在plaidml-setup设置的选择显卡的阶段不再选择显卡metal_intel®_uhd_graphics_630.0而是选择metal_amd_radeon_pro_5300m.0 (venv) tsingjtsingjdeMacBook-Pro-2 ~ # plaidml-setupPlaidML Setup (0.6.4)Thanks for using PlaidML!Some Notes:* Bugs and other issues: https://github.com/plaidml/plaidml* Questions: https://stackoverflow.com/questions/tagged/plaidml* Say hello: https://groups.google.com/forum/#!forum/plaidml-dev* PlaidML is licensed under the Apache License 2.0Default Config Devices:metal_intel(r)_uhd_graphics_630.0 : Intel(R) UHD Graphics 630 (Metal)metal_amd_radeon_pro_5300m.0 : AMD Radeon Pro 5300M (Metal)Experimental Config Devices:llvm_cpu.0 : CPU (LLVM)metal_intel(r)_uhd_graphics_630.0 : Intel(R) UHD Graphics 630 (Metal)opencl_amd_radeon_pro_5300m_compute_engine.0 : AMD AMD Radeon Pro 5300M Compute Engine (OpenCL)opencl_cpu.0 : Intel CPU (OpenCL)opencl_intel_uhd_graphics_630.0 : Intel Inc. Intel(R) UHD Graphics 630 (OpenCL)metal_amd_radeon_pro_5300m.0 : AMD Radeon Pro 5300M (Metal)Using experimental devices can cause poor performance, crashes, and other nastiness.Enable experimental device support? (y,n)[n]:nMultiple devices detected (You can override by setting PLAIDML_DEVICE_IDS). Please choose a default device:1 : metal_intel(r)_uhd_graphics_630.02 : metal_amd_radeon_pro_5300m.0Default device? (1,2)[1]:2Selected device:metal_amd_radeon_pro_5300m.0Almost done. Multiplying some matrices... Tile code:function (B[X,Z], C[Z,Y]) - (A) { A[x,y : X,Y] (B[x,z] * C[z,y]); } Whew. That worked.Save settings to /Users/tsingj/.plaidml? (y,n)[y]:y Success!step0 通过plaidml导入keras之后再做keras相关操作 # Importing PlaidML. Make sure you follow this order import plaidml.keras plaidml.keras.install_backend() import os os.environ[KERAS_BACKEND] plaidml.keras.backend注 1、在采用plaidml0.7.0 版本时plaidml.keras.install_backend()操作会发生报错 2、这步操作会通过plaidml导入keras将后台运算引擎设置为plaidml而不再采用tenserflow step1 先导入keras包导入数据cifar10 #!/usr/bin/env python import numpy as np import os import time import keras import keras.applications as kapp from keras.datasets import cifar10 (x_train, y_train_cats), (x_test, y_test_cats) cifar10.load_data() batch_size 8 x_train x_train[:batch_size] x_train np.repeat(np.repeat(x_train, 7, axis1), 7, axis2)step2 导入计算模型如果本地不存在该模型数据会自动进行下载 model kapp.VGG19()INFO:plaidml:Opening device “metal_amd_radeon_pro_5300m.0” 注意这里首次执行输入了显卡信息。 step3 模型编译 model.compile(optimizersgd, losscategorical_crossentropy,metrics[accuracy])step4 进行一次预测 print(Running initial batch (compiling tile program)) y model.predict(xx_train, batch_sizebatch_size)Running initial batch (compiling tile program) 由于输出较快内容打印只有一行。 step5 进行10次预测 # Now start the clock and run 10 batchesprint(Timing inference...) start time.time() for i in range(10):y model.predict(xx_train, batch_sizebatch_size)print(Ran in {} seconds.format(time.time() - start))查看输出 Ran in 0.43606019020080566 seconds Ran in 0.8583459854125977 seconds Ran in 1.2787911891937256 seconds Ran in 1.70143723487854 seconds Ran in 2.1235032081604004 seconds Ran in 2.5464580059051514 seconds Ran in 2.9677979946136475 seconds Ran in 3.390064001083374 seconds Ran in 3.8117799758911133 seconds Ran in 4.236911058425903 seconds 四、评估讨论 显卡metal_intel®_uhd_graphics_630.0的内存值为1536 MB虽然作为显卡其在进行运算中性能不及本机的 6核CPU 显卡metal_amd_radeon_pro_5300m.0内存值为4G其性能与本机 CPU对比提升将近 1 倍数。 由此可以看到对于采用 GPU在进行机器学习运算中的强大优势。
http://www.hkea.cn/news/14429387/

相关文章:

  • 自己有网站怎么优化北京建设公司网站
  • 怎么样在网站上做跳转会计专业建设规划
  • 建设分销网站免费seo培训
  • 品牌策划工作内容重庆百度提升优化
  • 做网站需要提供些什么页面自己建的网站百度查找不到
  • 工程网站模板云龙主机 wordpress
  • 如何做自已网站阿里巴巴seo站内优化方法
  • 生成二维码的网站返利网 网站建设费用
  • 海宁网站设计网站专栏建设
  • 大连网页网站制作张家港网站设计优化
  • 菏泽做网站建设找哪家建商城网站带app多少钱
  • 网站建设推广优化岗位说明书大连市住建局官网
  • 公司做网站的开支会计分录怎么做广州最新通知
  • 网站动态页面怎么做攀枝花网站开发
  • 网站建设属于网络还是软件公益事业做网站
  • 企业网站建设总体构架wordpress 外观菜单
  • 长沙电子商务网站建设小程序网站建设制作
  • 网站建设 模版选择中心医院网站asp
  • 备案信息修改网站名称东莞工商注册网站
  • 宜昌 网站建设网站开发设计文档
  • 行业门户网站系统全国最缺工100个职业表
  • 怎么上传文章网站网站建设的项目总结
  • 莱芜企业网站建设公司越秀五屏网站建设
  • 银河盛世网站建设深圳网站建设61916
  • wordpress建站全过程郑州网站制作推广公司
  • 移动网站建设机构广州科 外贸网站建设
  • 程序员代做网站违法桓台县网站建设
  • 什么静态网站容易做公司介绍
  • 专业做网站费用股票场外期权网站开发
  • 公司网站建设需要咨询什么问题设计网站有哪些