代码拉取完成,页面将自动刷新
The customized data transformation must inherited from BaseTransform
and implement transform
function.
Here we use a simple flipping transformation as example:
import random
import mmcv
from mmcv.transforms import BaseTransform, TRANSFORMS
@TRANSFORMS.register_module()
class MyFlip(BaseTransform):
def __init__(self, direction: str):
super().__init__()
self.direction = direction
def transform(self, results: dict) -> dict:
img = results['img']
results['img'] = mmcv.imflip(img, direction=self.direction)
return results
Moreover, import the new class.
from .my_pipeline import MyFlip
Thus, we can instantiate a MyFlip
object and use it to process the data dict.
import numpy as np
transform = MyFlip(direction='horizontal')
data_dict = {'img': np.random.rand(224, 224, 3)}
data_dict = transform(data_dict)
processed_img = data_dict['img']
Or, we can use MyFlip
transformation in data pipeline in our config file.
pipeline = [
...
dict(type='MyFlip', direction='horizontal'),
...
]
Note that if you want to use MyFlip
in config, you must ensure the file containing MyFlip
is imported during runtime.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。