PyTorch CNN 模型搭建示例:图像分类任务

以下代码示例展示了使用 PyTorch 搭建一个简单的 CNN 模型,用于图像分类任务。模型包含两层卷积层、池化层和全连接层,并详细解释了每一层的参数设置。

class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        self.conv1 = nn.Sequential(             # input shape (1,10000,12)
            nn.Conv2d(
                in_channels=1,  # input height
                out_channels=5,  # n_filters
                kernel_size=(200, 3),  # filter size
                stride=(50, 1),  # filter movement/step
                padding=1,
            ),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, padding=1),
        )
        self.conv2 = nn.Sequential(               # input shape (5,99,7)
            nn.Conv2d(5, 10, (20, 2), (4, 1), 1),  # output shape
            nn.ReLU(),                             # activation
            nn.MaxPool2d(kernel_size=2),                      # output shape (10,10,4)
        )
        self.out = nn.Linear(10 * 10 * 4, 6)      # fully connected layer, output 6 classes

该模型数据输入是 (100, 1, 10000, 12) 四维,该模型输入为几维内容?

该模型输入为四维,维度为 (100, 1, 10000, 12)。

PyTorch CNN 模型搭建示例:图像分类任务

原文地址: http://www.cveoy.top/t/topic/cFdz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录