MIC-DKFZ / batchgenerators

A framework for data augmentation for 2D and 3D image classification and segmentation
Apache License 2.0
1.09k stars 221 forks source link

Why the effect is not obvious? #32

Closed chengjianhong closed 5 years ago

chengjianhong commented 5 years ago

@FabianIsensee Hi, thanks for your excellent works. I try to use the data augmentation to train my brain tumor segmentation task. I have attempted many times to use Spatial Augmentationson my network(3D U-Net) during the training, but in terms of Dice, its effect is not obvious on testing data. The following code only works on the training dataset and the validation dataset does not augment it. The shapes of data and truth are (4,128,128,128) and (1,128,128,128). Can your give me some advices and how to improve it ?

def augment_spatial_data(data, truth, affine,batch_size):
    data_list = list()
    for data_index in range(data.shape[0]):
        image = get_image(data[data_index], affine)
        data_list.append(image.get_data())
    data = np.asarray(data_list)
    data = np.tile(data[None], (batch_size, 1, 1, 1, 1)).astype(np.float32)
    truth_image = get_image(truth, affine).get_data()
    truth_image = np.tile(truth_image[None,None], (batch_size, 1, 1, 1, 1)).astype(np.float32)
    data,truth=augment_spatial(data,truth_image,patch_size=truth.shape,
                       patch_center_dist_from_border=np.array(truth.shape)//2)
    data = np.tile(data[0], (1, 1, 1, 1))
    truth = np.tile(truth[0, 0], (1, 1, 1))
    return data,truth
FabianIsensee commented 5 years ago

Hi, isn't there the batch dimension missing on your shapes? Shouldn't it be (b,4,128,128,128)? Also I am not quite sure you are using this right. You are effectively showing the same example several times but with a spatial transformation applied to it. That may not be very effective. Please have a look at https://github.com/MIC-DKFZ/batchgenerators/blob/master/batchgenerators/examples/brats2017/brats2017_dataloader_3D.py

Best, Fabian

chengjianhong commented 5 years ago

Yes, I change the shape into (b,4,128,128,128) by np.tile() before performing spatial transformation. Comparaed with no spatial transformation ,it is not very effective. But thanks for your provided the brats example, I will try again.