Skip to content

Instantly share code, notes, and snippets.

@poxyu
poxyu / albumentations_targets.py
Last active October 4, 2018 06:50
Custom targets for albumentations
# import base class first
# or you'll get such error:
# TypeError: super(type, obj): obj must be an instance or subtype of type
from albumentations import DualTransform
# new targets function
def new_tf_targets(self):
return {
'image': self.apply, # do not rename this one
'image2': self.apply, # new
@jeasinema
jeasinema / spatial_softmax.py
Last active March 10, 2023 08:11
Spatial(Arg)Softmax for pytorch
import torch
import torch.nn.functional as F
from torch.nn.parameter import Parameter
import numpy as np
class SpatialSoftmax(torch.nn.Module):
def __init__(self, height, width, channel, temperature=None, data_format='NCHW'):
super(SpatialSoftmax, self).__init__()
self.data_format = data_format