cnn计算输入通道和输出通道

import torch
import torch.nn as nn
import torch.nn.functional as F

# 定义一个简单的CNN模型
class SimpleCNN(nn.Module):
    def __init__(self):
        super(SimpleCNN, self).__init__()
        # 第一个卷积层,输入通道数为1,输出通道数为6,卷积核大小为2
        self.conv1 = nn.Conv2d(3, 6, 2)
        # 最大池化层,池化窗口大小为2,步长为2
        self.pool = nn.MaxPool2d(2, 2)
        # 第二个卷积层,输入通道数为6,输出通道数为16,卷积核大小为2
        self.conv2 = nn.Conv2d(6, 16, 2)

        # 全连接层
        self.fc1 = nn.Linear(16 * 15 * 15, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        # x = self.conv1(x)
        # # breakpoint()
        # x = self.pool(x)
        # breakpoint()


        x = self.pool(F.relu(self.conv1(x)))  #(1,6,63,63) (1,6,31,31)
        x = self.pool(F.relu(self.conv2(x)))  #(1,16,30,30) (1,16,15,15)
        x = x.view(-1, 16 * 15 * 15)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

# 创建模型实例
model = SimpleCNN()

# 假设输入数据是一个32x32的灰度图像,batch size为1
input_data = torch.randn(1, 3, 64, 64)

# 将输入数据传递给模型
output = model(input_data)

# 打印输出数据的形状
print(output.shape)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值