[Python] The YOLOv1 model produces the same results for each image

Discussão em 'Python' iniciado por Stack, Janeiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    The model (Yolov1) is written in PyTorch. 30 epochs were trained, AdamOptimazer was used for training, learning rate = 1e-6, batch_size = 64. DeepScoresV2 dense dataset: 1362 photos in the training sample, I take only 3 classes from the dataset. But model returns the same result for all photos. What could possibly be the problem? The task is to identify the musical notation on the sheet of music, as well as to search for special signs (accolade and keys). Example ('Brace' appears in empty cells, this is an error of the function that outputs the image, everything is fine in the dataset itself): example

    Distribution of classes in the training sample (I take only 'brace', 'staff', and 'ottavaBracket' from them): classes

    Model Architecture:

    class ConvCombo(nn.Module):
    def __init__(self, in_channels: int, out_channels: int, kernel_size: int, stride: int = 1, padding=1):
    super().__init__()
    self._stack = nn.Sequential(
    nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=padding, bias=False),
    # nn.BatchNorm2d(out_channels),
    nn.LeakyReLU(0.1),
    )
    def forward(self, x):
    return self._stack(x)

    class YOLOv1(nn.Module):
    def __init__(self, S: int=7, C: int=20, B: int=2): # as it was in original article
    super().__init__()
    self._conv_stack = nn.Sequential(
    ConvCombo(in_channels=3, out_channels=64, kernel_size=S, stride=2, padding=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    ConvCombo(in_channels=64, out_channels=192, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    ConvCombo(in_channels=192, out_channels=128, kernel_size=1, padding=0),
    ConvCombo(in_channels=128, out_channels=256, kernel_size=3),
    ConvCombo(in_channels=256, out_channels=256, kernel_size=1, padding=0),
    ConvCombo(in_channels=256, out_channels=512, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    # x4 ->
    ConvCombo(in_channels=512, out_channels=256, kernel_size=1, padding=0),
    ConvCombo(in_channels=256, out_channels=512, kernel_size=3),
    ConvCombo(in_channels=512, out_channels=256, kernel_size=1, padding=0),
    ConvCombo(in_channels=256, out_channels=512, kernel_size=3),
    ConvCombo(in_channels=512, out_channels=256, kernel_size=1, padding=0),
    ConvCombo(in_channels=256, out_channels=512, kernel_size=3),
    ConvCombo(in_channels=512, out_channels=256, kernel_size=1, padding=0),
    ConvCombo(in_channels=256, out_channels=512, kernel_size=3),
    # <-
    ConvCombo(in_channels=512, out_channels=512, kernel_size=1, padding=0),
    ConvCombo(in_channels=512, out_channels=1024, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    # x2 ->
    ConvCombo(in_channels=1024, out_channels=512, kernel_size=1, padding=0),
    ConvCombo(in_channels=512, out_channels=1024, kernel_size=3),
    ConvCombo(in_channels=1024, out_channels=512, kernel_size=1, padding=0),
    ConvCombo(in_channels=512, out_channels=1024, kernel_size=3),
    # <-
    ConvCombo(in_channels=1024, out_channels=1024, kernel_size=3),
    ConvCombo(in_channels=1024, out_channels=1024, kernel_size=3, stride=2, padding=1),
    ConvCombo(in_channels=1024, out_channels=1024, kernel_size=3, padding=1),
    ConvCombo(in_channels=1024, out_channels=1024, kernel_size=3),
    )
    self._conn_stack = nn.Sequential(
    nn.Flatten(), # Flattens a contiguous range of dims into a tensor
    nn.Linear(in_features=(1024 * S * S), out_features=4096),
    nn.Dropout(0.0),
    nn.LeakyReLU(0.1),
    nn.Linear(in_features=4096, out_features=(S * S * (B * 5 + C))),
    )

    def forward(self, x):
    out = self._conv_stack(x)
    out = self._conn_stack(out)
    return out

    def process(self, x):
    return self(x)


    The result that the model outputs after training: results

    I'm trying to train the model to recognize musical notation and some other symbols, but the output gets the same predictions for each image. I have already tried to change the learning rate, but it has not yielded any results.

    Continue reading...

Compartilhe esta Página