Skip to content

Problem with the use of the dropout layer #4

@hwei-cs

Description

@hwei-cs

In your code, drop_out=True

self.up4 = SE_Conv_Block(filters[4], filters[3], drop_out=True)

self.conv4 = conv_block(filters[2], filters[3], drop_out=True)

self.center = conv_block(filters[3], filters[4], drop_out=True)

if self.dropout:
out = nn.Dropout2d(0.5)(out)

I think this line of code will affect the results when testing. Because you init the dropout layer in forward function, the model.eval() can not change the status of this layer.

You can test it with the following code

import torch
from torch import nn
import numpy as np

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.out = nn.Dropout2d(0.5)

    def forward(self, x):
        out = nn.Dropout2d(0.5)(x)
        # out = self.out(x)
        return out

if __name__ == '__main__':
    model = Net()
    model.eval()
    input_npy = np.array([[1.0, 2.0], [3.0, 4.0]])
    input_tensor = torch.from_numpy(input_npy)
    output = model(input_tensor)
    print(output)

If I didn't understand your code correctly, sorry in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions