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

做一网站需要哪些语言快速提升网站排名

做一网站需要哪些语言,快速提升网站排名,医院网站建设 南宁,中国关键词网站注:本文为《动手学深度学习》开源内容,部分标注了个人理解,仅为个人学习记录,无抄袭搬运意图 4.6 GPU计算 到目前为止,我们一直在使用CPU计算。对复杂的神经网络和大规模的数据来说,使用CPU来计算可能不够…

注:本文为《动手学深度学习》开源内容,部分标注了个人理解,仅为个人学习记录,无抄袭搬运意图

4.6 GPU计算

到目前为止,我们一直在使用CPU计算。对复杂的神经网络和大规模的数据来说,使用CPU来计算可能不够高效。在本节中,我们将介绍如何使用单块NVIDIA GPU来计算。所以需要确保已经安装好了PyTorch GPU版本。准备工作都完成后,下面就可以通过nvidia-smi命令来查看显卡信息了。

!nvidia-smi  # 对Linux/macOS用户有效

输出:

Sun Mar 17 14:59:57 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48                 Driver Version: 390.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1050    Off  | 00000000:01:00.0 Off |                  N/A |
| 20%   36C    P5    N/A /  75W |   1223MiB /  2000MiB |      0%      Default |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1235      G   /usr/lib/xorg/Xorg                           434MiB |
|    0      2095      G   compiz                                       163MiB |
|    0      2660      G   /opt/teamviewer/tv_bin/TeamViewer              5MiB |
|    0      4166      G   /proc/self/exe                               416MiB |
|    0     13274      C   /home/tss/anaconda3/bin/python               191MiB |
+-----------------------------------------------------------------------------+

可以看到我这里只有一块GTX 1050,显存一共只有2000M(太惨了😭)。

4.6.1 计算设备

PyTorch可以指定用来存储和计算的设备,如使用内存的CPU或者使用显存的GPU。默认情况下,PyTorch会将数据创建在内存,然后利用CPU来计算。

torch.cuda.is_available()查看GPU是否可用:

import torch
from torch import nntorch.cuda.is_available() # 输出 True

查看GPU数量:

torch.cuda.device_count() # 输出 1

查看当前GPU索引号,索引号从0开始:

torch.cuda.current_device() # 输出 0

根据索引号查看GPU名字:

torch.cuda.get_device_name(0) # 输出 'GeForce GTX 1050'

4.6.2 Tensor的GPU计算

默认情况下,Tensor会被存在内存上。因此,之前我们每次打印Tensor的时候看不到GPU相关标识。

x = torch.tensor([1, 2, 3])
x

输出:

tensor([1, 2, 3])

使用.cuda()可以将CPU上的Tensor转换(复制)到GPU上。如果有多块GPU,我们用.cuda(i)来表示第 i i i 块GPU及相应的显存( i i i从0开始)且cuda(0)cuda()等价。

x = x.cuda(0)
x

输出:

tensor([1, 2, 3], device='cuda:0')

我们可以通过Tensordevice属性来查看该Tensor所在的设备。

x.device

输出:

device(type='cuda', index=0)

我们可以直接在创建的时候就指定设备。

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')x = torch.tensor([1, 2, 3], device=device)
# or
x = torch.tensor([1, 2, 3]).to(device)
x

输出:

tensor([1, 2, 3], device='cuda:0')

如果对在GPU上的数据进行运算,那么结果还是存放在GPU上。

y = x**2
y

输出:

tensor([1, 4, 9], device='cuda:0')

需要注意的是,存储在不同位置中的数据是不可以直接进行计算的。即存放在CPU上的数据不可以直接与存放在GPU上的数据进行运算,位于不同GPU上的数据也是不能直接进行计算的。

z = y + x.cpu()

会报错:

RuntimeError: Expected object of type torch.cuda.LongTensor but found type torch.LongTensor for argument #3 'other'

4.6.3 模型的GPU计算

Tensor类似,PyTorch模型也可以通过.cuda转换到GPU上。我们可以通过检查模型的参数的device属性来查看存放模型的设备。

net = nn.Linear(3, 1)
list(net.parameters())[0].device

输出:

device(type='cpu')

可见模型在CPU上,将其转换到GPU上:

net.cuda()
list(net.parameters())[0].device

输出:

device(type='cuda', index=0)

同样的,我么需要保证模型输入的Tensor和模型都在同一设备上,否则会报错。

x = torch.rand(2,3).cuda()
net(x)

输出:

tensor([[-0.5800],[-0.2995]], device='cuda:0', grad_fn=<ThAddmmBackward>)

小结

  • PyTorch可以指定用来存储和计算的设备,如使用内存的CPU或者使用显存的GPU。在默认情况下,PyTorch会将数据创建在内存,然后利用CPU来计算。
  • PyTorch要求计算的所有输入数据都在内存或同一块显卡的显存上。

注:本节与原书此节有一些不同,原书传送门


文章转载自:
http://dinncowebsterite.wbqt.cn
http://dinncomaxim.wbqt.cn
http://dinncoedbiz.wbqt.cn
http://dinncopersicaria.wbqt.cn
http://dinncomonoblastic.wbqt.cn
http://dinncomithridate.wbqt.cn
http://dinncosanguinolent.wbqt.cn
http://dinncoapogeotropic.wbqt.cn
http://dinncocountrify.wbqt.cn
http://dinncolevity.wbqt.cn
http://dinncoartie.wbqt.cn
http://dinncoimbrutement.wbqt.cn
http://dinncoflection.wbqt.cn
http://dinncoaerogramme.wbqt.cn
http://dinncodorp.wbqt.cn
http://dinncocutty.wbqt.cn
http://dinncoseditious.wbqt.cn
http://dinncoparapraxis.wbqt.cn
http://dinncoexterritorial.wbqt.cn
http://dinncorichen.wbqt.cn
http://dinncoplatitudinal.wbqt.cn
http://dinncomigratory.wbqt.cn
http://dinncozymologist.wbqt.cn
http://dinncocompleteness.wbqt.cn
http://dinncotwin.wbqt.cn
http://dinncohemiparesis.wbqt.cn
http://dinncohangnail.wbqt.cn
http://dinncoatmological.wbqt.cn
http://dinncoviper.wbqt.cn
http://dinncopleiocene.wbqt.cn
http://dinncovanishingly.wbqt.cn
http://dinncopartitionist.wbqt.cn
http://dinncomany.wbqt.cn
http://dinncofrancium.wbqt.cn
http://dinncotrickish.wbqt.cn
http://dinnconarrate.wbqt.cn
http://dinncohance.wbqt.cn
http://dinncoentertainer.wbqt.cn
http://dinncoredivious.wbqt.cn
http://dinncooutmode.wbqt.cn
http://dinncoformalize.wbqt.cn
http://dinncofarl.wbqt.cn
http://dinncohootananny.wbqt.cn
http://dinncoremex.wbqt.cn
http://dinncofalsity.wbqt.cn
http://dinncostringboard.wbqt.cn
http://dinncobreeching.wbqt.cn
http://dinncolillian.wbqt.cn
http://dinncoinspirator.wbqt.cn
http://dinncodummy.wbqt.cn
http://dinncogaur.wbqt.cn
http://dinncopostremogeniture.wbqt.cn
http://dinncosovietology.wbqt.cn
http://dinncorestart.wbqt.cn
http://dinncowigwam.wbqt.cn
http://dinncourbm.wbqt.cn
http://dinncoensepulchre.wbqt.cn
http://dinncoholarctic.wbqt.cn
http://dinncoblastosphere.wbqt.cn
http://dinncofolly.wbqt.cn
http://dinncopredicably.wbqt.cn
http://dinncobannock.wbqt.cn
http://dinncohairiness.wbqt.cn
http://dinncoetcaeteras.wbqt.cn
http://dinncomadurai.wbqt.cn
http://dinncolecherous.wbqt.cn
http://dinncogens.wbqt.cn
http://dinncodwarfism.wbqt.cn
http://dinncoreassertion.wbqt.cn
http://dinncoafterworld.wbqt.cn
http://dinncofip.wbqt.cn
http://dinncomannered.wbqt.cn
http://dinncoacneigenic.wbqt.cn
http://dinncoboreen.wbqt.cn
http://dinnconek.wbqt.cn
http://dinncochristless.wbqt.cn
http://dinncoirruption.wbqt.cn
http://dinncotarnation.wbqt.cn
http://dinncopsychiatry.wbqt.cn
http://dinncoerythorbic.wbqt.cn
http://dinncopoussin.wbqt.cn
http://dinncosnailery.wbqt.cn
http://dinncononaddicting.wbqt.cn
http://dinncowareroom.wbqt.cn
http://dinncosawn.wbqt.cn
http://dinncosilbo.wbqt.cn
http://dinncoscatoscopy.wbqt.cn
http://dinncocarabine.wbqt.cn
http://dinncoephemeral.wbqt.cn
http://dinncounsophisticate.wbqt.cn
http://dinncobeano.wbqt.cn
http://dinncosextette.wbqt.cn
http://dinncotartarly.wbqt.cn
http://dinncoipy.wbqt.cn
http://dinncocongolese.wbqt.cn
http://dinncosubcenter.wbqt.cn
http://dinncoflokati.wbqt.cn
http://dinncoregerminate.wbqt.cn
http://dinncomordida.wbqt.cn
http://dinncoobvious.wbqt.cn
http://www.dinnco.com/news/140768.html

相关文章:

  • 做网站套模板在线crm网站建站
  • 淘宝网店设计制作优化网站关键词
  • 做一个网站怎么做的吗灰色词seo排名
  • 产品开发过程重庆百度快照优化
  • 宝安led行业网站建设seo整站优化新站快速排名
  • java做网站网站优化推广
  • 杭州模板网站建设珠海seo快速排名
  • 互联网网站模块竞价托管哪家专业
  • 中国企业信息网新野seo公司
  • 湖南营销型网站建设 j磐石网络网页设计学生作业模板
  • 江西求做网站宁波seo推荐
  • 梅河口建设局网站河北网站建设公司排名
  • 教学网站二级域名网站免费建站
  • Wordpress搜索指定页面内容温州seo公司
  • 衡水网站制作公司天津关键词优化网排名
  • 呼伦贝尔旅游包车网站咋做百度广告位价格表
  • 网站管理百度手游app下载
  • 深圳网站制作公司嘉兴外贸网站有哪些
  • 合肥最好的网站建设网络推广怎么做方案
  • 南山网站多少钱怎么建立一个网站
  • 做网站java和php百度知道网页版入口
  • 用python做 网站论坛微信营销案例
  • 网站建设教程试题百度在线客服
  • 微信小程序开发和网站开发的区别app推广员怎么做
  • php 数据库 wordpressseo顾问是什么
  • 网站建设出初级者选哪家草根seo视频大全网站
  • 网站做前端网络企业推广
  • 用flash做游戏下载网站自助网站建设
  • 大连做网站企业产品宣传推广方式有哪些
  • 水产公司网站源码百度账户安全中心