-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added DropBlock implementation (#53)
* feat: Added DropBlock implementation * docs: Updated documentation * test: Added unittest
- Loading branch information
Showing
6 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
from .loss import * | ||
from .downsample import * | ||
from .conv import * | ||
from .dropblock import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
''' | ||
Regularization modules | ||
''' | ||
|
||
import torch | ||
import torch.nn as nn | ||
from .. import functional as F | ||
|
||
__all__ = ['DropBlock2d'] | ||
|
||
|
||
class DropBlock2d(nn.Module): | ||
"""Implements the DropBlock module from `"DropBlock: A regularization method for convolutional networks" | ||
<https://arxiv.org/pdf/1810.12890.pdf>`_ | ||
Args: | ||
p (float): probability of dropping activation value | ||
block_size (int): size of each block that is expended from the sampled mask | ||
inplace (bool, optional): whether the operation should be done inplace | ||
""" | ||
|
||
def __init__(self, p, block_size, inplace=False): | ||
super().__init__() | ||
self.p = p | ||
self.block_size = block_size | ||
self.inplace = inplace | ||
|
||
@property | ||
def drop_prob(self): | ||
return self.p / self.block_size ** 2 | ||
|
||
def forward(self, x): | ||
return F.dropblock2d(x, self.drop_prob, self.block_size, self.inplace) | ||
|
||
def extra_repr(self): | ||
return f"p={self.p}, block_size={self.block_size}, inplace={self.inplace}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters