def map_arg(**maps):
    """
    Apply a mapping on certain argument before calling the original function.

    Args:
        maps (dict): {argument_name: map_func}
    """
    def deco(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            # getcallargs was deprecated since 3.5
            sig = inspect.signature(func)
            argmap = sig.bind_partial(*args, **kwargs).arguments
            for k, map_func in maps.items():
                if k in argmap:
                    argmap[k] = map_func(argmap[k])
            return func(**argmap)
        return wrapper
    return deco

    Apply a mapping on certain argument before calling the original function.

    Args:
        maps (dict): {argument_name: map_func}
    
tensorpack/utils/argtools.py