# Copyright (C) 2019-2022, François-Guillaume Fernandez.# This program is licensed under the Apache License 2.0.# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details.importtorch.nnasnnfromtorchimportTensorfrom..importfunctionalasF__all__=["DropBlock2d"]
[docs]classDropBlock2d(nn.Module):"""Implements the DropBlock module from `"DropBlock: A regularization method for convolutional networks" <https://arxiv.org/pdf/1810.12890.pdf>`_ .. image:: https://github.com/frgfm/Holocron/releases/download/v0.1.3/dropblock.png :align: center Args: p (float, optional): probability of dropping activation value block_size (int, optional): 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:float=0.1,block_size:int=7,inplace:bool=False)->None:super().__init__()self.p=pself.block_size=block_sizeself.inplace=inplace@propertydefdrop_prob(self)->float:returnself.p/self.block_size**2defforward(self,x:Tensor)->Tensor:returnF.dropblock2d(x,self.drop_prob,self.block_size,self.inplace,self.training)defextra_repr(self)->str:returnf"p={self.p}, block_size={self.block_size}, inplace={self.inplace}"