代码
import torch
import torch.nn as nn
# 定义 1x1 卷积
conv1x1 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=1)
# 输入特征图,假设其形状为 (batch_size, in_channels, height, width)
input_tensor = torch.randn(1, 128, 64, 64)
# 应用 1x1 卷积
output_tensor = conv1x1(input_tensor)
# 输出的形状将为 (batch_size, out_channels, height, width)
print(output_tensor.shape) # 输出: torch.Size([1, 256, 64, 64])