Help with model

username: Samuel_Bachorik
cooked: <p>Hello, i am using dataset for detection of road that consist of 500 training images and masks. When other guys used this dataset they had PERFECT results and let me show you my result.<br>
Result of training -  <a href="https://www.youtube.com/watch?v=OzMFVTIYNNc" class="inline-onebox" rel="noopener nofollow ugc">output - YouTube</a></p>
<p>I want to ask if you can help with this model, what to improve on this model to get better results? I tried all possible learning rates and epochs. So this is problem in model not in training. Thank you.</p>
<p>I am using this model for it.</p>
<pre><code class="lang-auto">def double_conv(in_channels, out_channels):
    return nn.Sequential(
        nn.Conv2d(in_channels, out_channels, 3, padding=1),
        torch.nn.BatchNorm2d(out_channels),
        nn.ReLU(inplace=True),
        nn.Conv2d(out_channels, out_channels, 3, padding=1),
        torch.nn.BatchNorm2d(out_channels),
        nn.ReLU(inplace=True)
    )

class Model(nn.Module):
    def __init__(self, n_class=5):
        super(Model).__init__()

        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

        self.dconv_down1 = double_conv(3, 64)
        self.dconv_down2 = double_conv(64, 128)
        self.dconv_down3 = double_conv(128, 256)
        self.dconv_down4 = double_conv(256, 512)

        self.maxool = nn.MaxPool2d(2)
        self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)

        self.dconv_up3 = double_conv(256 + 512, 256)
        self.dconv_up2 = double_conv(128 + 256, 128)
        self.dconv_up1 = double_conv(128 + 64, 64)

        self.conv_last = nn.Conv2d(64, n_class, 1)

    def forward(self, x):
        conv1 = self.dconv_down1(x)
        x = self.maxpool(conv1)

        conv2 = self.dconv_down2(x)
        x = self.maxpool(conv2)

        conv3 = self.dconv_down3(x)
        x = self.maxpool(conv3)

        x = self.dconv_down4(x)

        x = self.upsample(x)
        x = torch.cat([x, conv3], dim=1)

        x = self.dconv_up3(x)
        x = self.upsample(x)
        x = torch.cat([x, conv2], dim=1)

        x = self.dconv_up2(x)
        x = self.upsample(x)
        x = torch.cat([x, conv1], dim=1)

        x = self.dconv_up1(x)

        out = self.conv_last(x)

        return out
</code></pre>

username: ptrblck
cooked: <p>I don’t know which criterion you are using, but adding the dice loss might help for segmentation use cases.<br>
Also, you could try to add skip connections into your conv blocks, which seemed to work out pretty well in the past.</p>

username: Samuel_Bachorik
cooked: <p>Hello, thank you for reply, iam using this type of loss- MSE</p>
<pre><code class="lang-auto">loss = ((y - y_pred) ** 2).mean()
</code></pre>
<p>Please can you give me example how to use “dice loss” ? I was searching on internet but I didn’t get any solution for this model.</p>

username: ptrblck
cooked: <p>Assuming you are working on a multi-class segmentation use case, I would use <code>nn.CrossEntropyLoss</code> as the “base” loss instead of <code>MSELoss</code>.<br>
For the dice loss implementation, you could have a look at <a href="https://github.com/pytorch/pytorch/issues/1249">this issue</a> or the implementation from <a href="https://kornia.readthedocs.io/en/v0.1.2/_modules/torchgeometry/losses/dice.html">torchgeometry</a>.</p>