def test_Dropout(self): p = 0.2 input = torch.Tensor(1000).fill_(1 - p) module = nn.Dropout(p) output = module.forward(input) self.assertLess(abs(output.mean() - (1 - p)), 0.05) gradInput = module.backward(input, input) self.assertLess(abs(gradInput.mean() - (1 - p)), 0.05) module = nn.Dropout(p, True) output = module.forward(input.clone()) self.assertLess(abs(output.mean() - (1 - p)), 0.05) gradInput = module.backward(input.clone(), input.clone()) self.assertLess(abs(gradInput.mean() - (1 - p)), 0.05) # Check that these don't raise errors module.__repr__() str(module)
nn.Conv2d(32, 96, (5, 5), (1, 1), (2, 2)), nn.ReLU(), nn.MaxPool2d((3, 3), (1, 1), (1, 1), ceil_mode=True), nn.Conv2d(256, 64, (1, 1)), nn.ReLU(), nn.MaxPool2d((3, 3), (2, 2), (0, 0), ceil_mode=True), nn.Conv2d(480, 192, (1, 1)), nn.ReLU(), nn.Conv2d(480, 96, (1, 1)), nn.ReLU(), nn.Conv2d(96, 208, (3, 3), (1, 1), (1, 1)), nn.ReLU(), nn.Conv2d(480, 16, (1, 1)), nn.ReLU(), nn.Conv2d(16, 48, (5, 5), (1, 1), (2, 2)), nn.ReLU(), nn.MaxPool2d((3, 3), (1, 1), (1, 1), ceil_mode=True), nn.Conv2d(480, 64, (1, 1)), nn.ReLU(), nn.AvgPool2d((5, 5), (3, 3), (0, 0), ceil_mode=True), #AvgPool2d, nn.Conv2d(512, 128, (1, 1)), nn.ReLU(), Lambda(lambda x: x.view(x.size(0), -1)), # View, nn.Sequential(Lambda(lambda x: x.view(1, -1) if 1 == len(x.size()) else x), nn.Linear(2048, 1024)), # Linear, nn.ReLU(), nn.Dropout(0.7), nn.Sequential(Lambda(lambda x: x.view(1, -1) if 1 == len(x.size()) else x), nn.Linear(1024, 365)), # Linear, )