# Buggy code
def __init__(
    self,
    transforms,
    bbox_params=None,
    keymap=None,
    update_pad_shape=False,
    skip_img_without_anno=False,
):
    if Compose is None:
        raise RuntimeError("albumentations is not installed")

    self.transforms = transforms
    self.filter_lost_elements = False
    self.update_pad_shape = update_pad_shape
    self.skip_img_without_anno = skip_img_without_anno

    # A simple workaround to remove masks without boxes
    if (
        isinstance(bbox_params, dict)
        and "label_fields" in bbox_params
        and "filter_lost_elements" in bbox_params
    ):
        self.filter_lost_elements = True
        self.origin_label_fields = bbox_params["label_fields"]
        bbox_params["label_fields"] = ["idx_mapper"]
        del bbox_params["filter_lost_elements"]

    self.bbox_params = self.albu_builder(bbox_params) if bbox_params else None
    self.aug = Compose(
        [self.albu_builder(t) for t in self.transforms], bbox_params=self.bbox_params
    )

    if not keymap:
        self.keymap_to_albu = {
            "img": "image",
            "gt_masks": "masks",
            "gt_bboxes": "bboxes",
        }
    else:
        self.keymap_to_albu = keymap
    self.keymap_back = {v: k for k, v in self.keymap_to_albu.items()}


# Traceback (ValueError)
Original Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/content/mmdetection/mmdet/datasets/custom.py", line 193, in __getitem__
data = self.prepare_train_img(idx)
File "/content/mmdetection/mmdet/datasets/custom.py", line 216, in prepare_train_img
return self.pipeline(results)
File "/content/mmdetection/mmdet/datasets/pipelines/compose.py", line 40, in __call__
data = t(data)
File "/content/mmdetection/mmdet/datasets/pipelines/transforms.py", line 1344, in __call__
results = self.aug(**results)
File "/usr/local/lib/python3.6/dist-packages/albumentations/core/composition.py", line 170, in __call__
p.ensure_data_valid(data)
File "/usr/local/lib/python3.6/dist-packages/albumentations/augmentations/bbox_utils.py", line 37, in ensure_data_valid
raise ValueError("Your 'label_fields' are not valid - them must have same names as params in dict")
ValueError: Your 'label_fields' are not valid - them must have same names as params in dict

# Fixed code
def __init__(
    self,
    transforms,
    bbox_params=None,
    keymap=None,
    update_pad_shape=False,
    skip_img_without_anno=False,
):
    if Compose is None:
        raise RuntimeError("albumentations is not installed")

    # Args will be modified later, copying it will be safer
    transforms = copy.deepcopy(transforms)
    if bbox_params is not None:
        bbox_params = copy.deepcopy(bbox_params)
    if keymap is not None:
        keymap = copy.deepcopy(keymap)
    self.transforms = transforms
    self.filter_lost_elements = False
    self.update_pad_shape = update_pad_shape
    self.skip_img_without_anno = skip_img_without_anno

    # A simple workaround to remove masks without boxes
    if (
        isinstance(bbox_params, dict)
        and "label_fields" in bbox_params
        and "filter_lost_elements" in bbox_params
    ):
        self.filter_lost_elements = True
        self.origin_label_fields = bbox_params["label_fields"]
        bbox_params["label_fields"] = ["idx_mapper"]
        del bbox_params["filter_lost_elements"]

    self.bbox_params = self.albu_builder(bbox_params) if bbox_params else None
    self.aug = Compose(
        [self.albu_builder(t) for t in self.transforms], bbox_params=self.bbox_params
    )

    if not keymap:
        self.keymap_to_albu = {
            "img": "image",
            "gt_masks": "masks",
            "gt_bboxes": "bboxes",
        }
    else:
        self.keymap_to_albu = keymap
    self.keymap_back = {v: k for k, v in self.keymap_to_albu.items()}