用于回归问题的 PyTorch 模型,每个样本 4 个图像,图像之间有时间间隔

问题描述 投票:0回答:1

我正在使用一个数据集,其中每个样本对应于以已知延迟拍摄的 4 个图像,并且每组 4 个图像都有一个目标预测,该目标预测是一个数字(不是分类)。我目前已经制作了下面的模型,但它根本没有给出好的结果。有什么建议吗?

class SimpleModel(nn.Module):
    def __init__(self):
        super(SimpleModel, self).__init__()
        
        self.conv1 = nn.Conv2d(in_channels=4, out_channels=8, kernel_size=3, stride=1, padding=1)
        self.bn1 = nn.BatchNorm2d(8)
        self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
        self.dropout1 = nn.Dropout(p=0.25)
        
        self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1)
        self.bn2 = nn.BatchNorm2d(16)
        self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
        self.dropout2 = nn.Dropout(p=0.25)
        
        self.conv3 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=1)
        self.bn3 = nn.BatchNorm2d(32)
        self.pool3 = nn.MaxPool2d(kernel_size=5, stride=2)
        self.dropout3 = nn.Dropout(p=0.25)
        
        self.flatten = nn.Flatten()
        self.fc1 = nn.Linear(28800, 512)
        self.dropout4 = nn.Dropout(p=0.5)
        self.fc2 = nn.Linear(512, 1)  # Single output

    def forward(self, x):
        x = torch.relu(self.bn1(self.conv1(x)))
        x = self.pool1(x)
        x = self.dropout1(x)
        
        x = torch.relu(self.bn2(self.conv2(x)))
        x = self.pool2(x)
        x = self.dropout2(x)
        
        x = torch.relu(self.bn3(self.conv3(x)))
        x = self.pool3(x)
        x = self.dropout3(x)
        
        x = self.flatten(x)
        x = torch.relu(self.fc1(x))
        x = self.dropout4(x)
        
        x = self.fc2(x)  # Output layer, no activation function for regression
        return x

此外,目标预测值通常非常小,有时甚至大得多,例如从 1e-9 到 1e2 左右。我已将对数标度应用于目标预测,以减少这种影响,以尝试改进学习,但不确定它有多大帮助。

machine-learning deep-learning pytorch
1个回答
0
投票

[...]它根本没有给出好的结果

是验证数据还是训练数据?

如果训练损失没有下降,则可能表明学习管道存在问题。我首先确认该模型能够通过将训练集大小减少到几个样本来进行学习,并确保训练损失减少(并且训练score非常高)。这将证明该模型能够学习一些东西。

在确认模型可以学习后,如果你给模型更多的样本,它的训练损失会更高一点,训练分数会下降一点,但你应该开始看到验证分数有所提高。

一些快速检查:

  • Adam
    是一个很好的默认优化器
  • loss适合回归,比如MSE或者类似
  • 输入数据应进行缩放

您的输入图像尺寸约为 680 x 680?尝试增加 input 卷积层的内核大小,以捕获更多空间信息(我认为 5x5 和 7x7 在输入处是典型的)。

© www.soinside.com 2019 - 2024. All rights reserved.