latentspace.

Dropout


  • Dropout
  • 
        import torch
        torch.random.manual_seed(777)
    
        rand_3x3 = torch.rand(size=(3, 3))
        print(rand_3x3)
        # > tensor([[0.0819, 0.4911, 0.4033],
        #           [0.3859, 0.8813, 0.8811],
        #           [0.7242, 0.5033, 0.8249]])
    
        dropout = torch.nn.Dropout(p=0.5, inplace=False)
        rand_3x3_dropped = dropout(rand_3x3)
        print(rand_3x3_dropped)
        # > tensor([[0.1638, 0.0000, 0.0000],
        #           [0.7718, 1.7626, 0.0000],
        #           [1.4485, 0.0000, 0.0000]])
    
        dropout.eval()
        print(dropout(rand_3x3))
        # > tensor([[0.0819, 0.4911, 0.4033],
        #           [0.3859, 0.8813, 0.8811],
        #           [0.7242, 0.5033, 0.8249]])