You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
파일경로 : mmsegmentation > mmseg > datasets > pipelines > transforms.py 파일 안에 Albumentation 코드를 추가
pipelines > __init__.py에 Albu 클래스를 import를 하면 됨.
Details
아래 코드를 transforms.py 에 추가하면 됩니다. 이후 config datasets에서 mmdetection에서 albumentation 사용했던 것처럼 사용하면 됩니다.
importcopyimportmmcvimportnumpyasnpfrommmcv.utilsimportdeprecated_api_warning, is_tuple_offromnumpyimportrandomfrom ..builderimportPIPELINEStry:
importalbumentationsfromalbumentationsimportComposeexceptImportError:
albumentations=NoneCompose=None@PIPELINES.register_module()classAlbu(object):
"""Albumentation augmentation. Adds custom transformations from Albumentations library. Please, visit `https://albumentations.readthedocs.io` to get more information. An example of ``transforms`` is as followed: .. code-block:: [ dict( type='ShiftScaleRotate', shift_limit=0.0625, scale_limit=0.0, rotate_limit=0, interpolation=1, p=0.5), dict( type='RandomBrightnessContrast', brightness_limit=[0.1, 0.3], contrast_limit=[0.1, 0.3], p=0.2), dict(type='ChannelShuffle', p=0.1), dict( type='OneOf', transforms=[ dict(type='Blur', blur_limit=3, p=1.0), dict(type='MedianBlur', blur_limit=3, p=1.0) ], p=0.1), ] Args: transforms (list[dict]): A list of albu transformations keymap (dict): Contains {'input key':'albumentation-style key'} """def__init__(self, transforms, keymap=None, update_pad_shape=False):
# Args will be modified later, copying it will be safertransforms=copy.deepcopy(transforms)
ifkeymapisnotNone:
keymap=copy.deepcopy(keymap)
self.transforms=transformsself.filter_lost_elements=Falseself.update_pad_shape=update_pad_shapeself.aug=Compose([self.albu_builder(t) fortinself.transforms])
ifnotkeymap:
self.keymap_to_albu= {'img': 'image', 'gt_semantic_seg': 'mask'}
else:
self.keymap_to_albu=keymapself.keymap_back= {v: kfork, vinself.keymap_to_albu.items()}
defalbu_builder(self, cfg):
"""Import a module from albumentations. It inherits some of :func:`build_from_cfg` logic. Args: cfg (dict): Config dict. It should at least contain the key "type". Returns: obj: The constructed object. """assertisinstance(cfg, dict) and'type'incfgargs=cfg.copy()
obj_type=args.pop('type')
ifmmcv.is_str(obj_type):
obj_cls=getattr(albumentations, obj_type)
else:
raiseTypeError(f'type must be str, but got {type(obj_type)}')
if'transforms'inargs:
args['transforms'] = [
self.albu_builder(transform)
fortransforminargs['transforms']
]
returnobj_cls(**args)
@staticmethoddefmapper(d, keymap):
"""Dictionary mapper. Renames keys according to keymap provided. Args: d (dict): old dict keymap (dict): {'old_key':'new_key'} Returns: dict: new dict. """updated_dict= {}
fork, vinzip(d.keys(), d.values()):
new_k=keymap.get(k, k)
updated_dict[new_k] =d[k]
returnupdated_dictdef__call__(self, results):
# dict to albumentations formatresults=self.mapper(results, self.keymap_to_albu)
results=self.aug(**results)
# back to the original formatresults=self.mapper(results, self.keymap_back)
# update final shapeifself.update_pad_shape:
results['pad_shape'] =results['img'].shapereturnresultsdef__repr__(self):
repr_str=self.__class__.__name__+f'(transforms={self.transforms})'returnrepr_str
The text was updated successfully, but these errors were encountered:
Background
Content
mmsegmentation > mmseg > datasets > pipelines > transforms.py
파일 안에 Albumentation 코드를 추가pipelines > __init__.py
에 Albu 클래스를 import를 하면 됨.Details
아래 코드를 transforms.py 에 추가하면 됩니다. 이후 config datasets에서 mmdetection에서 albumentation 사용했던 것처럼 사용하면 됩니다.
The text was updated successfully, but these errors were encountered: