def apply_all(x, func):
    """
    Apply a function to a list of tensors/images or a single tensor/image
    """
    if isinstance(x, list) or isinstance(x, tuple):
        return [func(t) for t in x]
    else:
        return func(x)