I am working on an underwater image detection problem using detection2. I have applied an image enhancement augmentation offline (by storing the newly processed data in a separate folder). But I need to apply the image enhancement on the fly, such that it is fed into the model during training time (with some probability). I tried integrating this module on the fly but it's taking too much time. Can anybody help me to resolve this issue? I am using RetinaNet as a backbone. I tried the following:
def map_enhance(dataset_dict):
dataset_dict = copy.deepcopy(dataset_dict) # it will be modified by code below
# can use other ways to read image
image = utils.read_image(dataset_dict["file_name"], format="BGR")
# Apply some image enhancement technique:
# Create the format that the model expects:
return {"image": image,
"instances": utils.annotations_to_instances(annos, image.shape[1:]),
"width": image.shape[1],
"height": image.shape[2]}
class TrainerEnhance(DefaultTrainer):
@classmethod
def build_train_loader(cls, cfg):
if cfg.INPUT.ENHANCE_IMAGE:
mapper = DatasetMapper(cfg, is_train=True, augmentations=[map_enhance])
else:
mapper = None
return build_detection_train_loader(cfg, mapper=mapper)
But unfortunately, that did not work!