“Adjacent pixels” refer to the values of an entire channel, which would be dropped using nn.Dropout2d, while nn.Dropout would drop random pixel locations as seen here:

x = torch.randn(2, 2, 4, 4)
drop = nn.Dropout2d()
out = drop(x)
print(out)
> tensor([[[[ 0.0000,  0.0000, -0.0000, -0.0000],
            [-0.0000, -0.0000,  0.0000, -0.0000],
            [-0.0000,  0.0000,  0.0000,  0.0000],
            [-0.0000, -0.0000,  0.0000,  0.0000]],

           [[-1.7700,  0.5395,  1.1095,  1.5484],
            [-1.5528, -0.6495,  1.5294,  0.6949],
            [-1.5919,  0.3380,  2.6201,  2.0743],
            [-1.5087,  0.5487, -0.4077,  1.1598]]],


          [[[-5.5042, -0.3527, -0.1202,  1.6333],
            [ 1.9476, -1.1323,  1.2164, -1.9838],
            [ 1.9263,  1.0842, -1.4239, -0.8705],
            [ 2.7384,  1.5202,  2.0018, -1.3804]],

           [[ 0.0000, -0.0000,  0.0000, -0.0000],
            [ 0.0000,  0.0000, -0.0000,  0.0000],
            [ 0.0000,  0.0000,  0.0000,  0.0000],
            [-0.0000,  0.0000,  0.0000,  0.0000]]]])

drop = nn.Dropout()
out = drop(x)
print(out)
> tensor([[[[ 1.3324,  0.0000, -0.0000, -0.0000],
            [-0.9783, -0.0000,  0.0000, -4.8274],
            [-0.0000,  2.1448,  0.1935,  0.0000],
            [-0.6435, -0.0000,  2.8480,  0.2524]],

           [[-0.0000,  0.0000,  0.0000,  1.5484],
            [-1.5528, -0.6495,  0.0000,  0.0000],
            [-0.0000,  0.0000,  2.6201,  0.0000],
            [-0.0000,  0.0000, -0.4077,  0.0000]]],


          [[[-0.0000, -0.3527, -0.1202,  0.0000],
            [ 0.0000, -0.0000,  0.0000, -0.0000],
            [ 0.0000,  1.0842, -1.4239, -0.8705],
            [ 2.7384,  1.5202,  0.0000, -0.0000]],

           [[ 2.2113, -0.5281,  3.7269, -1.7598],
            [ 0.0000,  0.0000, -0.0000,  0.0000],
            [ 3.0427,  0.0000,  0.0000,  0.0000],
            [-0.0000,  0.4729,  0.0000,  0.0000]]]])

The purpose is best explained in the Dropout paper, which explains it can help avoiding “co-adaption”. The specified probability is a hyperparameter and specifies the drop probability.

The in_features of a linear layer are defined by the number of features of the flattened input activation. Since nn.Conv2d layers output a 4-dimensional tensor in the shape [batch_size, channels, height, width], you would specify the in_features of the linear layer as channels*height*width and flatten the activation via nn.Flatten() or manually via x = x.view(x.size(0), -1).