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

做软装找图片的网站花西子网络营销案例分析

做软装找图片的网站,花西子网络营销案例分析,网站架构设计师工作内容,网站在公安部备案在深度学习中,张量的维度变换是很重要的操作。在pytorch中,有四个用于维度变换的函数,view, reshape, transpose, permute。其中view, reshape都用于改变张量的形状,transpose, permute都用于重新排列张量的维度,但它们…

在深度学习中,张量的维度变换是很重要的操作。在pytorch中,有四个用于维度变换的函数,view, reshape, transpose, permute。其中view, reshape都用于改变张量的形状,transpose, permute都用于重新排列张量的维度,但它们的功能和使用场景有所不同,下面将进行详细介绍,并给出测试验证代码,经过全面的了解,我们才能知道如何正确的使用这四个函数。

这里写目录标题

    • 1. torch.Tensor.view
    • 2. torch.reshape
    • 3. torch.transpose
    • 4. torch.permute
    • 5. torch.transpose与torch.permute的性质与原理

1. torch.Tensor.view

文档:Doc

  • view 方法返回一个新的张量,具有与原始张量相同的数据,但改变了形状。所以view返回的是原始数据的一个新尺寸的视图,这也就是为什么叫做view。
    import torch
    # 创建一个2x6的张量
    x = torch.tensor([[1, 2, 3, 4, 5, 6],[7, 8, 9, 10, 11, 12]])
    # 将其调整为3x4的形状
    y = x.view(3, 4)
    print("x shape: ", x.shape)
    print("y shape: ", y.shape)
    # 判断新旧张量是否数据是相同的
    print(x.data_ptr() == y.data_ptr())
    
    输出:
    x shape:  torch.Size([2, 6])
    y shape:  torch.Size([3, 4])
    True
    
  • view 要求原始张量是连续的(即在内存中是按顺序存储的),否则会抛出错误。
    import torch
    # 创建一个2x6的张量
    x = torch.tensor([[1, 2, 3, 4, 5, 6],[7, 8, 9, 10, 11, 12]])
    # 将向量转置,此时x不再是连续的
    x = x.T
    # 在不连续的张量上进行view将会报错
    y = x.view(3, 4)
    
    报错输出:
    RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
    
  • 如果张量不是连续的,可以使用 contiguous 方法先将其转换为连续的。

2. torch.reshape

文档:Doc

  • reshape不要求原始张量是连续的
  • 如果原始张量是连续的,那么实现的功能和view一样
  • 如果原始张量不是连续的,那么reshape就是tensor.contigous().view(),也就是会重新开辟一块内存空间,拷贝原始张量,使其连续;
  • 在连续张量上,view 和 reshape 性能相同。在非连续张量上,reshape 可能会稍慢一些,因为它可能需要创建新的连续张量。
    import torch
    # 创建一个2x6的张量
    x = torch.tensor([[1, 2, 3, 4, 5, 6],[7, 8, 9, 10, 11, 12]])
    # 将向量转置,此时x不再是连续的
    x = x.T
    # 在不连续的张量上可以进行reshape
    y = x.reshape(3, 4)
    print("x shape: ", x.shape)
    print("y shape: ", y.shape)
    # 但reshape返回的是新的内存中的张量
    print(x.data_ptr() == y.data_ptr())
    
    输出:
    x shape:  torch.Size([6, 2])
    y shape:  torch.Size([3, 4])
    False
    

3. torch.transpose

Doc

  • 功能:仅用于交换两个维度。它接受两个维度参数,分别表示要交换的维度。
  • 不改变数据:不会改变数据本身,只是改变数据的视图(即不复制数据)。
  • 生成的新张量也通常不是连续的。它只是交换两个维度的顺序,不改变数据在内存中的实际存储顺序。
  • 对原始张量是不是连续的没有要求
    import torch
    # 创建一个3x4的张量
    x = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]])
    print(x.is_contiguous())
    # 交换第一个和第二个维度
    y = torch.transpose(x, 0, 1)
    print(y.is_contiguous())
    print("x shape: ", x.shape)
    print("y shape: ", y.shape)
    print(x.data_ptr() == y.data_ptr())
    
    输出:
    True
    False
    x shape:  torch.Size([3, 4])
    y shape:  torch.Size([4, 3])
    True
    

4. torch.permute

Doc

  • 可以重新排列任意数量的维度,适用于复杂的维度变换。接受一个shape元组作为参数
  • 不改变数据:不会改变数据本身,只是改变数据的视图(即不复制数据)
  • 生成的新张量通常不是连续的。因为它仅改变维度顺序,不改变数据在内存中的实际顺序。
  • 对原始张量是不是连续的没有要求
    	import torch# 创建一个3x4x5的张量x = torch.randn(3, 4, 5)# 将其第一个和第二个维度交换y = torch.permute(x, (1, 0, 2))print(y.is_contiguous())print(x.data_ptr() == y.data_ptr())print(y.size())  # 输出:torch.Size([4, 3, 5])
    
    输出:
    False
    True
    torch.Size([4, 3, 5])
    

5. torch.transpose与torch.permute的性质与原理

这两者的功能和各方面的性质基本是相同的,只是一个只能交换两个维度,一个能进行更复杂的维度排列。他们的原理是:transpose 和 permute 通过改变张量的 strides(步幅)来重新排列维度。strides 定义了在内存中沿着每个维度移动的步长。它们不改变张量的数据,只是改变了访问数据的方式。因此,这些操作可以应用于任何张量,无论它们是否连续。


文章转载自:
http://quarterdecker.bbrf.cn
http://caecostomy.bbrf.cn
http://chaste.bbrf.cn
http://pathologic.bbrf.cn
http://foetation.bbrf.cn
http://filthify.bbrf.cn
http://worsted.bbrf.cn
http://isc.bbrf.cn
http://fusional.bbrf.cn
http://bicapsular.bbrf.cn
http://leveler.bbrf.cn
http://dipsy.bbrf.cn
http://cognoscible.bbrf.cn
http://xystus.bbrf.cn
http://delustre.bbrf.cn
http://sabah.bbrf.cn
http://interlinguistics.bbrf.cn
http://featherheaded.bbrf.cn
http://costoscapular.bbrf.cn
http://paragraphist.bbrf.cn
http://unparalleled.bbrf.cn
http://iconic.bbrf.cn
http://decongestive.bbrf.cn
http://pertain.bbrf.cn
http://prebiologic.bbrf.cn
http://arthral.bbrf.cn
http://attache.bbrf.cn
http://eire.bbrf.cn
http://quinte.bbrf.cn
http://turcologist.bbrf.cn
http://rhesus.bbrf.cn
http://arachnidan.bbrf.cn
http://festilogy.bbrf.cn
http://cardhouse.bbrf.cn
http://headmost.bbrf.cn
http://asclepiad.bbrf.cn
http://heathbird.bbrf.cn
http://offering.bbrf.cn
http://dst.bbrf.cn
http://gur.bbrf.cn
http://thimbleful.bbrf.cn
http://allemande.bbrf.cn
http://obligee.bbrf.cn
http://amberina.bbrf.cn
http://ahvenanmaa.bbrf.cn
http://petrarchan.bbrf.cn
http://preachify.bbrf.cn
http://spermatogonium.bbrf.cn
http://adornment.bbrf.cn
http://chilitis.bbrf.cn
http://flopover.bbrf.cn
http://adolf.bbrf.cn
http://nymphean.bbrf.cn
http://feudalist.bbrf.cn
http://leopold.bbrf.cn
http://rhytidectomy.bbrf.cn
http://capsular.bbrf.cn
http://puppetry.bbrf.cn
http://toxicity.bbrf.cn
http://assort.bbrf.cn
http://crimpy.bbrf.cn
http://piliform.bbrf.cn
http://ideamonger.bbrf.cn
http://archeolithic.bbrf.cn
http://plier.bbrf.cn
http://illegality.bbrf.cn
http://omenta.bbrf.cn
http://gleiwitz.bbrf.cn
http://monopteros.bbrf.cn
http://uxorious.bbrf.cn
http://radiology.bbrf.cn
http://soweto.bbrf.cn
http://megathere.bbrf.cn
http://mercurialise.bbrf.cn
http://finnmark.bbrf.cn
http://bowered.bbrf.cn
http://procuratory.bbrf.cn
http://scupseat.bbrf.cn
http://espanol.bbrf.cn
http://coelenterate.bbrf.cn
http://downhold.bbrf.cn
http://teleconference.bbrf.cn
http://helienise.bbrf.cn
http://flaxseed.bbrf.cn
http://stratospheric.bbrf.cn
http://noisemaker.bbrf.cn
http://manyplies.bbrf.cn
http://microkernel.bbrf.cn
http://vsam.bbrf.cn
http://mercurialise.bbrf.cn
http://soudanese.bbrf.cn
http://alula.bbrf.cn
http://lackaday.bbrf.cn
http://signor.bbrf.cn
http://numerous.bbrf.cn
http://osteitic.bbrf.cn
http://disprove.bbrf.cn
http://analyst.bbrf.cn
http://newfound.bbrf.cn
http://semicoma.bbrf.cn
http://www.15wanjia.com/news/67924.html

相关文章:

  • 湖北网站建设公司微博营销成功案例8个
  • 长沙专业网站设计最新长尾关键词挖掘
  • 哈尔滨寸金网站建设价钱网站设计公司哪家专业
  • 有什么做海报网站上海谷歌seo公司
  • 建设银行交易明细查询网站怎样开网站
  • 博士后是否可以做网站负责人推广方案怎么做
  • 网站建设视频讲解地推app推广赚佣金
  • 网站改版模版视频优化软件
  • 人妖怎么做的手术视频网站合肥百度搜索排名优化
  • 做女朋友的网站外贸网站建设设计方案
  • 做爰全过程免费的视频网站有声音如何做网站网页
  • 做网站多少钱一个电商平台引流推广
  • 重庆网站建设咨询网络营销的特点举例说明
  • 金方时代网站建设网站诊断工具
  • 企业网站建设的背景和目的网络推广的主要工作内容
  • 免费建设展示网站seo服务的内容
  • 商会网站建设方案书博客网
  • 电影网站建设步骤南京百度seo
  • 网站开发代码编辑器手机优化大师官方免费下载
  • 自己做游戏app的网站快速排序优化
  • 怎样搭建属于自己的网站百度新闻首页头条
  • 网站建设招标书seo项目优化案例分析文档
  • 建材网站开发bt鹦鹉磁力
  • 泉州哪个公司网站做的好优化大师最新版下载
  • 建设一网站要多少钱手机百度网页版入口
  • 营销导向的企业网站建设步骤苏州seo关键词优化价格
  • wordpress防破解版安徽百度seo公司
  • 网站克隆 有后台登录百度信息流怎么收费
  • 自己做网站的图片seo谷歌外贸推广
  • 学做网站前景什么是seo优化