def _save_image(image, output_dir, filename, fmt):
    """Saves an image in the output directory."""
    target = os.path.join(output_dir, filename)
    _ensure_dir(target)
    try:
        # try to save the image with the specified format or
        # derive the format from the filename (if format=None)
        image.save(target, format=fmt)
    except ValueError:
        # could not determine format from filename
        image.save(target, format="png")
Saves an image in the output directory.
lightly/data/dataset.py