[Python] Model with ResNet blocks stuck at low accuracy

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to implement classification of ECG segments from PTB-XL database (https://physionet.org/content/ptb-xl/1.0.3/). The architecture of the model which I am using is:

    import torch
    import torch.nn as nn

    class ResNetBlock(nn.Module):
    def __init__(self, in_channels, out_channels):
    super().__init__()
    self.conv1 = nn.Conv1d(in_channels, out_channels, kernel_size=7, padding=3,stride=1)
    self.bn1 = nn.BatchNorm1d(out_channels)
    self.conv2 = nn.Conv1d(out_channels, out_channels, kernel_size=5, padding=2,stride=1)
    self.bn2 = nn.BatchNorm1d(out_channels)
    self.conv3 = nn.Conv1d(in_channels=out_channels,out_channels=out_channels,kernel_size=3,padding=1,stride=1)
    self.bn3 = nn.BatchNorm1d(out_channels)
    skip_layers = []
    if in_channels != out_channels:
    skip_layers += [
    nn.Conv1d(in_channels, out_channels, kernel_size=1, stride=1),
    nn.BatchNorm1d(out_channels)
    ]
    self.skip_bn = nn.BatchNorm1d(out_channels)
    self.skip = nn.Sequential(*skip_layers)

    self.relu = nn.ReLU(inplace=True)


    class Model(nn.Module):
    def __init__(self,in_channels,num_classes):
    super().__init__()
    self.block_sizes = [64,128,256]
    self.resnet_block1 = ResNetBlock(in_channels=in_channels,out_channels=self.block_sizes[0])
    self.resnet_block2 = ResNetBlock(in_channels=self.block_sizes[0],out_channels=self.block_sizes[1])

    self.resnet_block3 = ResNetBlock(in_channels=self.block_sizes[1],out_channels=self.block_sizes[2])

    self.global_pool = nn.AdaptiveAvgPool1d(1)
    self.fc1 = nn.Linear(self.block_sizes[2], num_classes)


    Results that model is showing are rather confusing, because the model is stuck at 47% training accuracy, and around 46% testing accuracy. What I tried was adding nn.Dropout(0.2) after every resnet block but it didn't help at all. I tried all sorts of combinations for learning_rate, from 0.01 to 0.00001, and I tried various batch_sizes ([32,64,128,256]), but I am stuck. Any help would be well appreciated.

    Continue reading...

Compartilhe esta Página