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

淘宝网站营销推广方案ppt案例

淘宝网站,营销推广方案ppt案例,文档做网站,免费教育网站建设目录 神经网络的基本骨架 卷积操作 torch.nn.functional.conv2d 神经网络的基本骨架 搭建Neural Network骨架主要用到的包是torch.nn,官方文档网址:torch.nn — PyTorch 2.0 documentation,其中torch.nn.Module很重要,是所有所…

目录

神经网络的基本骨架

卷积操作 torch.nn.functional.conv2d


神经网络的基本骨架

搭建Neural Network骨架主要用到的包是torch.nn,官方文档网址:torch.nn — PyTorch 2.0 documentation,其中torch.nn.Module很重要,是所有所有神经网络模块的基类(即自己搭建的网络必须继承torch.nn.Module基类),官方文档地址:Module — PyTorch 2.0 documentation。

搭建模型时,集成torch.nn.Module后必须要重写两个函数:__init__()forward()

import torch.nn as nn
import torch.nn.functional as Fclass Model(nn.Module):def __init__(self):super().__init__()self.conv1 = nn.Conv2d(1, 20, 5)self.conv2 = nn.Conv2d(20, 20, 5)def forward(self, x):x = F.relu(self.conv1(x))return F.relu(self.conv2(x))

卷积操作 torch.nn.functional.conv2d

torch.nn包含了torch.nn.functional,两者中都包含了Conv、Pool等层操作,且用法和效果都是一样的(但是具体的输入参数有所不同)。用的torch.nn.functional.conv2d举例,但其实在以后使用中,torch.nn.Conv2d更常用。

torch.nn.functional.conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) → Tensor
CLASS torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode=‘zeros’, device=None, dtype=None)

torch.nn.functional.conv2d中的Input、weight(也就是kernel)都必须是4维张量,每维的含义是[batch_size, C, H, W],必要的时候,可用reshape()或unsqueeze()对张量进行扩维。
(1) reshape是对改变tensor的形状,各维度的乘积与原本保持一致。
(2) unsqueeze是在指定维度上扩充一个1维。
 

import torchx = torch.arange(15)
x2 = torch.reshape(x, [3, 5])	# 用list或tuple表示形状都可以
y1_reshape = torch.reshape(x, [1, 1, 3, 5])  # reshape:只要所有维度乘在一起的积不变,就可以任意扩充多个维度
y2_unsqueeze = torch.unsqueeze(x2, 2)	# unsequeeze:第二个参数的数据类型是int,所以只能在指定维度上扩充一个1维(升维)
c_squeeze = torch.squeeze(y1_reshape)	# sequeeze:只传入一个tensor参数,然后将tensor的所有1维删掉(降维)print('x.shape:{}'.format(x.shape))
print('x2.shape:{}'.format(x2.shape))
print('y1_reshape.shape:{}'.format(y1_reshape.shape))
print('y2_unsqueeze.shape:{}'.format(y2_unsqueeze.shape))
print('c_squeeze.shape:{}'.format(c_squeeze.shape))
import torch
import torch.nn.functional as Finput = torch.tensor([[1, 2, 0, 3, 1],[0, 1, 2, 3, 1],[1, 2, 1, 0, 0],[5, 2, 3, 1, 1],[2, 1, 0, 1, 1]])
kernel = torch.tensor([[1, 2, 1],[0, 1, 0],[2, 1, 0]])print(input.shape)
print(kernel.shape)# input、kernel都扩充到4维
input = torch.reshape(input, (1, 1, 5, 5))
kernel = torch.reshape(kernel, (1, 1, 3, 3))out = F.conv2d(input, kernel, stride=1)
print('out={}'.format(out))out2 = F.conv2d(input, kernel, stride=2)
print('out2={}'.format(out2))out3 = F.conv2d(input, kernel, stride=1, padding=1)
print('out3={}'.format(out3))


 

http://www.tj-hxxt.cn/news/90813.html

相关文章:

  • 做seo网站的公司哪家好重庆官网seo分析
  • 电子商务网站建设a卷培训计划模板
  • 南阳建设网站制作自助建站系统下载
  • 百万网站建设报价软文写作平台发稿
  • 做的比较好的教育网站宁波seo网络推广咨询价格
  • 做网站的组要具备哪些素质乐云seo
  • 国内做网站最大的公司重庆整站seo
  • 用网站还是阿里巴巴做soho上海怎么做seo推广
  • 怎么利用国外网站做互联网挣钱网盘资源免费观看
  • 销售软件有哪些企业搜索引擎优化
  • 网站什么时候做解析手游cpa推广平台
  • 做网站seo优化网站建设的基本
  • 网站开发和游戏开发微信小程序免费制作平台
  • 素材网站免费短视频qq群排名优化软件购买
  • 做网站logo用啥软件最近有新病毒出现吗
  • 河北建设网站怎么下载企业锁广告资源网
  • 2018数字政府建设论坛网站北京百度seo关键词优化
  • 计算机大二建设网站南京seo优化培训
  • 聊城市住房和城乡建设委员会门户网站对网站提出的优化建议
  • 网站界面 ui 设计答案百度推广客户端app
  • 网站支付宝怎么做教育培训班
  • 做网站不要盲目跟风关键词推广排名
  • 个人做网站的流程宁波网站推广平台效果好
  • 长春哪里有做网站的如何去推广
  • 郴州品牌网站建设推广黄冈网站推广
  • 高级web程序设计——asp.net网站开发课后答案最近重大新闻
  • 适合中考做的微机题网站一个网站推广
  • 广州那家做网站最好常见的网络营销方法
  • 苏州专业做网站公司哪家好产品营销网站建设
  • 怎么给网站做友情链接快速网站排名提升工具