558. Vesuvius Challenge - Ink Detection | vesuvius-challenge-ink-detection
[
A.HorizontalFlip(p=0.5),
A.VerticalFlip(p=0.5),
A.RandomRotate90(p=0.5),
A.Affine(rotate=0, translate_percent=0.1, scale=[0.9,1.5], shear=0, p=0.5),
A.OneOf([
A.RandomToneCurve(scale=0.3, p=0.2),
A.RandomBrightnessContrast(brightness_limit=(-0.1, 0.2), contrast_limit=(-0.4, 0.5), brightness_by_max=True, always_apply=False, p=0.8)
], p=0.5),
A.OneOf([
A.ShiftScaleRotate(shift_limit=None, scale_limit=[-0.15, 0.15], rotate_limit=[-30, 30], interpolation=cv2.INTER_LINEAR, border_mode=cv2.BORDER_CONSTANT, value=0, mask_value=None, shift_limit_x=[-0.1, 0.1], shift_limit_y=[-0.2, 0.2], rotate_method='largest_box', p=0.5),
A.ElasticTransform(alpha=1, sigma=20, alpha_affine=10, interpolation=cv2.INTER_LINEAR, border_mode=cv2.BORDER_CONSTANT, value=0, mask_value=None, approximate=False, same_dxdy=False, p=0.5),
A.GridDistortion(num_steps=5, distort_limit=0.3, interpolation=cv2.INTER_LINEAR, border_mode=cv2.BORDER_CONSTANT, value=0, mask_value=None, normalized=True, p=0.5),
], p=0.5),
A.OneOf([
A.GaussNoise(var_limit=[10, 50], p=0.5),
A.GaussianBlur(p=0.5),
A.MotionBlur(p=0.5),
], p=0.5),
A.CoarseDropout(max_holes=3, max_width=0.15, max_height=0.25, mask_fill_value=0, p=0.5),
A.Normalize(
mean=[0]*in_chans,
std=[1]*in_chans,
),
ToTensorV2(transpose_mask=True),
]
class AttentionPool(torch.nn.Module):
def __init__(self, depth, height, width):
super().__init__()
self.attention_weights = nn.Parameter(torch.ones(1, 1, depth, height, width))
self.softmax = nn.Softmax(dim=2)
def forward(self, x):
# 沿深度维度应用softmax获取注意力权重
attention_weights = self.softmax(self.attention_weights)
# 通过注意力权重与输入相乘实现注意力池化
pooled_output = torch.mul(attention_weights, x)
# 沿深度维度求和
pooled_output = torch.sum(pooled_output, dim=2)
return pooled_output
if cfg.use_denoiser:
self.denoiser = smp.Unet(
encoder_name="tu-resnet10t", # "tu-resnet10t" 或 "resnet18"
encoder_weights="imagenet",
in_channels=1,
classes=1,
activation=None,
)
# 推理阶段
if self.cfg.use_denoiser:
noise = self.denoiser(masks)
masks = masks - noise