-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
questionFurther information is requestedFurther information is requested
Milestone
Description
I need a spatial transform for MIL that takes an input (ndarray) NxCxWxH,
loops over the first dimension (patches) and randomly flips (see below)
What are my options with the current monai functionality?
- I understand that in the previous transform I can output a list of dicts (each having one patch) to be able to use RandomFlip (form monai). But in this case I don't know how to handle "label", all these patches have the same label (class) and I suppose I could repeat the same label (as a workaround) in each dict, but then at the end I need to recombine (concat) these patches and have only 1 single label
furthermore, the output of all transforms should be in the 5D shape BxNxCxWxH (where B is the batch dim, N is number of patches). and with this workaround, I get 4D: BNxCxWxH, and labels will be mixed up too
- sequential application of several flips, creates copies , which I'm trying to avoid
class BatchedRandFlip():
def __init__( self, keys, p=0.5) :
super().__init__()
self.keys = keys
self.p=p
def __call__(self, data):
d = dict(data)
for key in self.keys:
images = d[key]
images2=[]
for i in range(images.shape[0]):
img = images[i]
if np.random.random() > self.p: img = np.flip(img, axis=1)
if np.random.random() > self.p: img = np.flip(img, axis=2)
if np.random.random() > self.p: img = np.transpose(img, axes=(0,2,1))
images2.append(img)
d[key] = np.stack(images2, axis=0)
return d
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested