yelusaleng / RRU-Net

Official repository for "RRU-Net: The Ringed Residual U-Net for Image Splicing Forgery Detection" (CVPRW 2019)
106 stars 17 forks source link

Data Augmentation #9

Closed Gianfranco-98 closed 3 years ago

Gianfranco-98 commented 3 years ago

Hi! In the original paper "RRU-Net: The Ringed Residual U-Net for Image Splicing Forgery Detection" it is told that data augmentation has been applied. In particular, the data augmentation is composed by Random Gaussian Noise, JPEG Compression and Random Overturn.

The problem is that I can't see any function handling this tasks in this implementation. Why it's not performed?

yelusaleng commented 3 years ago

@Gianfranco-98 hi, i think the implementation of the data augmentation is simple, and u can design a suitable augmentation method manually.

Gianfranco-98 commented 3 years ago

Thank you for the answer.

Yes, I think it too, but did you use any type of augmentation when training your model? Or did you just trained the net on the Plain Splicing Dataset without apply other transformations?

yelusaleng commented 3 years ago

actually, the dataset was augmented before training, u can refer to the following script.

from albumentations.augmentations.transforms import (
    VerticalFlip, HorizontalFlip, JpegCompression, GaussNoise, RandomRotate90
)
from skimage import io
import os
from tqdm import tqdm
from random import choice

path_img = './data_Forensics/train/tam/'
path_mask = './data_Forensics/train/mask/'

for i in tqdm(os.listdir(path_img)):
    name = i.split('.')[0]
    img = os.path.join(path_img, i)
    mask = os.path.join(path_mask, '{}_mask.png'.format(name))
    image = io.imread(img)
    mask = io.imread(mask)

    list_quality = [50, 60, 70, 80, 90]
    quality = choice(list_quality)
    io.imsave(os.path.join(path_img, '{}_q.jpg'.format(name)), image, quality=quality)
    io.imsave(os.path.join(path_mask, '{}_q_mask.png'.format(name)), mask)

    whatever_data = "my name"

    augmentation = VerticalFlip(p=1.0)
    data = {"image": image, "mask": mask, "whatever_data": whatever_data, "additional": "hello"}
    augmented = augmentation(**data)
    image_ver, mask_ver, whatever_data, additional = augmented["image"], augmented["mask"], augmented["whatever_data"], augmented["additional"]
    io.imsave(os.path.join(path_img, '{}_ver.jpg'.format(name)), image_ver, quality=100)
    io.imsave(os.path.join(path_mask, '{}_ver_mask.png'.format(name)), mask_ver)

    augmentation = HorizontalFlip(p=1.0)
    data = {"image": image, "mask": mask, "whatever_data": whatever_data, "additional": "hello"}
    augmented = augmentation(**data)
    image_hor, mask_hor, whatever_data, additional = augmented["image"], augmented["mask"], augmented["whatever_data"], augmented["additional"]
    io.imsave(os.path.join(path_img, '{}_hor.jpg'.format(name)), image_hor, quality=100)
    io.imsave(os.path.join(path_mask, '{}_hor_mask.png'.format(name)), mask_hor)

    augmentation = GaussNoise(var_limit=(10, 50), p=1.0)
    data = {"image": image, "mask": mask, "whatever_data": whatever_data, "additional": "hello"}
    augmented = augmentation(**data)
    image_g, mask_g, whatever_data, additional = augmented["image"], augmented["mask"], augmented["whatever_data"], augmented["additional"]
    io.imsave(os.path.join(path_img, '{}_G.jpg'.format(name)), image_g, quality=100)
    io.imsave(os.path.join(path_mask, '{}_G_mask.png'.format(name)), mask_g)
Gianfranco-98 commented 3 years ago

Perfect, thank you!