def __init__(self, in_channels, out_channels, kernel_size=3, activation=None, upsampling=1): super().__init__() self.s1 = nn.Sequential(nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2), nn.UpsamplingBilinear2d(scale_factor=upsampling) if upsampling > 1 else nn.Identity(), Activation(activation)) self.s2 = nn.Sequential(nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2), nn.UpsamplingBilinear2d(scale_factor=upsampling) if upsampling > 1 else nn.Identity(), Activation(activation)) self.s3 = nn.Sequential(nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2), nn.UpsamplingBilinear2d(scale_factor=upsampling) if upsampling > 1 else nn.Identity(), Activation(activation)) self.s4 = nn.Sequential(nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2), nn.UpsamplingBilinear2d(scale_factor=upsampling) if upsampling > 1 else nn.Identity(), Activation(activation))
def __init__( self, encoder_weights: str = None, encoder_freeze: bool = True, decoder_use_batchnorm: bool = True, decoder_channels: List[int] = (256, 128, 64, 32, 16), classes: int = 1, activation: Optional[Union[str, callable]] = "sigmoid", device=torch.device("cpu"), ): super().__init__() self.encoder = moco_r50(encoder_weights, encoder_freeze=encoder_freeze, map_location=device) self.decoder = UnetDecoder( encoder_channels=(12, 64, 256, 512, 1024, 2048), decoder_channels=decoder_channels, n_blocks=5, use_batchnorm=decoder_use_batchnorm, center=False, attention_type=None, ) self.segmentation_head = torch.nn.Sequential( torch.nn.AdaptiveAvgPool2d((1, 1)), torch.nn.Flatten(), torch.nn.Linear(16, classes), Activation(activation), ) self.classification_head = None self.initialize()
def __init__(self, in_channels, out_channels, kernel_size=3): conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, padding=kernel_size // 2) identity = nn.Identity() activation = Activation(None) super().__init__(conv2d, identity, activation)
def __init__(self, eps=1., activation=None, ignore_channels=None, **kwargs): super().__init__(**kwargs) self.eps = eps self.activation = Activation(activation) self.ignore_channels = ignore_channels
def __init__(self, eps=1e-7, threshold=0.5, activation=None, ignore_channels=None, **kwargs): super().__init__(**kwargs) self.eps = eps self.threshold = threshold self.activation = Activation(activation) self.ignore_channels = ignore_channels
def __init__(self, eps=1., alf=0.3, beta=0.7, activation=None, ignore_channels=None, **kwargs): super().__init__(**kwargs) self.eps = eps self.alf = alf self.beta = beta self.activation = Activation(activation) self.ignore_channels = ignore_channels
def __init__(self, bce=1.0, dice=0.5, lovasz=0.0, soft_bce=True): super().__init__() if soft_bce: self.bce = losses.soft_bce.SoftBCEWithLogitsLoss(smooth_factor=0.1) else: self.bce = nn.BCEWithLogitsLoss() self.dice = DiceLoss(activation=None) self.lovasz = losses.lovasz.LovaszLoss(mode='binary', from_logits=False) self.activation = Activation('sigmoid') self.w_bce = bce self.w_dice = dice self.w_lovasz = lovasz
def __init__(self, eps=1., beta=1., weight=1, activation=None, ignore_channels=None, **kwargs): super().__init__(**kwargs) self.eps = eps self.beta = beta self.activation = Activation(activation) self.ignore_channels = ignore_channels self.weight = weight
def __init__(self, in_channels, out_channels, kernel_size=3, activation=None, upsampling=1): dropout = nn.Dropout2d(0.5) conv2d = nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, padding=kernel_size // 2) upsampling = nn.UpsamplingBilinear2d( scale_factor=upsampling) if upsampling > 1 else nn.Identity() activation = Activation(activation) super().__init__(dropout, conv2d, upsampling, activation)