当前位置:网站首页 > TensorFlow框架 > 正文

conv2d参数(conv2d参数解释TensorFlow)



import torch

import torch.nn.functional as F

# 创建一个 5x5 的二维张量作为输入

input = 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]])

# 创建一个 3x3 的二维张量作为卷积核

kernel = torch.tensor([[1, 2, 1],

                       [0, 1, 0],

                       [2, 1, 0]])

# 重塑 input 和 kernel 张量以符合 conv2d 的期望输入格式

# conv2d 需要输入的形状为 (batch_size, channels, height, width)

input = torch.reshape(input, (1, 1, 5, 5))

kernel = torch.reshape(kernel, (1, 1, 3, 3))

# 打印 input 和 kernel 的形状以确认变换

print(input.shape)  # 输出: torch.Size([1, 1, 5, 5])

print(kernel.shape)  # 输出: torch.Size([1, 1, 3, 3])

# 应用 conv2d 函数进行卷积操作,步长为 1

output = F.conv2d(input, kernel, stride=1)

print(output)  # 输出卷积结果

# 应用 conv2d 函数进行卷积操作,步长为 2

output2 = F.conv2d(input, kernel, stride=2)

print(output2)  # 输出卷积结果

# 应用 conv2d 函数进行卷积操作,步长为 1,同时添加 padding

# padding=1 表示在输入张量的边界添加一圈宽度为 1 的零填充

output3 = F.conv2d(input, kernel, stride=1, padding=1)

print(output3)  # 输出卷积结果

import torch import torchvision from torch import nn from torch.utils.data import DataLoader from torchvision.ops.misc import Conv2d #获取数据 dataset=torchvision.datasets.CIFAR10("https://blog.csdn.net/m0_/article/data",train=False,transform=torchvision.transforms.ToTensor(), download=True) #封装数据,加载数据 dataloader=DataLoader(dataset,batch_size=64) #卷积神经 class CR(nn.Module): def __init__(self): super(CR,self).__init__() #kernel_size 定义卷积核大小 self.conv1=Conv2d(in_channels=3,out_channels=6,kernel_size=3,stride=1,padding=0) def forward(self,x): x=self.conv1(x) return x cr=CR() print(cr)

到此这篇conv2d参数(conv2d参数解释TensorFlow)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • ddd领域驱动模型设计(ddd领域模型框架搭建)2024-12-07 12:18:09
  • 微信hook机器人框架(微信机器人 框架)2024-12-07 12:18:09
  • 如何编写富文本框(富文本编辑器框架)2024-12-07 12:18:09
  • 流量回放系统(流量回放框架)2024-12-07 12:18:09
  • 模型框架结构(模型 框架)2024-12-07 12:18:09
  • 模型框架结构(框架和模型的区别)2024-12-07 12:18:09
  • 流量回放框架(流量回放框架怎么用)2024-12-07 12:18:09
  • conv2d参数解释(conv2d参数解释TensorFlow)2024-12-07 12:18:09
  • 模型 框架(模型框架图是什么)2024-12-07 12:18:09
  • 微信hook框架有那些(微信hook开源)2024-12-07 12:18:09
  • 全屏图片