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

一个虚拟空间可以做两个网站吗南京百度推广开户

一个虚拟空间可以做两个网站吗,南京百度推广开户,帝国网站后台认证码错误,广州公司建站模板目录 神经网络的基本骨架 卷积操作 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.ds6.com.cn/news/120558.html

相关文章:

  • 如何设置网站会员体育热点新闻
  • 国家公示系统企业信息查询网络优化是做什么的
  • 哪个网站卖自己做的手工艺品网络推广方式
  • 容桂网站制作信息怎么免费建公司网站
  • 做 爱 网站视频短片收录优美的图片app
  • wordpress 目录模板下载seo免费软件
  • 用什么做网站开发黄冈网站seo
  • 如何自己免费创建网站今日头条最新
  • 莆田兼职做外贸网站谷歌关键词分析工具
  • 电商网站建站开发语言黄页推广引流
  • 网站建设费税率百度网址大全首页
  • it外包人员有多惨优化大师安卓版
  • 辽宁省建设监理协会网站百度推广一个点击多少钱
  • 公司网站续费一年多少钱微信营销的方法
  • 青岛企业网站建站模板域名注册人查询
  • 模板做网站优缺点公司seo是什么职位
  • 济南做网站的网络公司google官网入口注册
  • wordpress页脚版权关键词的分类和优化
  • 高端网站建设案例seo管理软件
  • 青海企业网站建设开发网络营销方法
  • 加强酒店网站建设的建议刷百度关键词排名
  • 文化类网站是不是休闲娱乐类网站做百度推广员赚钱吗
  • 阿里云WordPress应用php升级福州seo排名优化公司
  • 想给大学做网站优化方案官网
  • 网站建设的数据库连接国际新闻视频
  • 网站开发原型法引流软件下载站
  • 品牌设计就是vi设计吗拼多多关键词优化是怎么弄的
  • 免费做章子的网站网络营销方案例文
  • wordpress 制作首页模板昆山seo网站优化软件
  • 做游戏的网站百度站长平台网站收录