in fvcore/transforms/transform.py [0:0]
def register_type(cls, data_type: str, func: Optional[Callable] = None):
"""
Register the given function as a handler that this transform will use
for a specific data type.
Args:
data_type (str): the name of the data type (e.g., box)
func (callable): takes a transform and a data, returns the
transformed data.
Examples:
.. code-block:: python
# call it directly
def func(flip_transform, voxel_data):
return transformed_voxel_data
HFlipTransform.register_type("voxel", func)
# or, use it as a decorator
@HFlipTransform.register_type("voxel")
def func(flip_transform, voxel_data):
return transformed_voxel_data
# ...
transform = HFlipTransform(...)
transform.apply_voxel(voxel_data) # func will be called
"""
if func is None: # the decorator style
def wrapper(decorated_func):
assert decorated_func is not None
cls.register_type(data_type, decorated_func)
return decorated_func
return wrapper
assert callable(
func
), "You can only register a callable to a Transform. Got {} instead.".format(
func
)
argspec = inspect.getfullargspec(func)
assert len(argspec.args) == 2, (
"You can only register a function that takes two positional "
"arguments to a Transform! Got a function with spec {}".format(str(argspec))
)
setattr(cls, "apply_" + data_type, func)