# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from dlinputs import utils
import numpy as np

assert utils.make_gray(np.zeros((400, 300, 3))).shape == (400, 300)
assert utils.make_gray(np.zeros((400, 300))).shape == (400, 300)
assert utils.make_gray(np.zeros((400, 300, 4))).shape == (400, 300)

assert utils.make_rgb(np.zeros((400, 300, 3))).shape == (400, 300, 3)
assert utils.make_rgb(np.zeros((400, 300))).shape == (400, 300, 3)
assert utils.make_rgb(np.zeros((400, 300, 4))).shape == (400, 300, 3)

assert utils.make_rgba(np.zeros((400, 300, 3))).shape == (400, 300, 4)
assert utils.make_rgba(np.zeros((400, 300))).shape == (400, 300, 4)
assert utils.make_rgba(np.zeros((400, 300, 4))).shape == (400, 300, 4)

d = dict(a=1, b=2, c=3)
rd = utils.invert_mapping(d)
assert rd[1] == "a"

d = utils.get_string_mapping("a=x:b=y:c=z")
assert d["a"] == "x"

image = np.zeros((400, 300, 3))
png = utils.pildumps(image)
image1 = utils.pilreads(png, "rgb")
assert image.shape == image1.shape
assert (image == image1).all()

image = np.zeros((400, 300, 3))
png = utils.pildumps(image)
image1 = utils.pilreads(png, "gray")
assert image.shape[:2] == image1.shape

sample = dict(png=np.zeros((400, 300, 3)))
raw = utils.autoencode(sample)
sample1 = utils.autodecode(raw)
assert (sample["png"] == sample1["png"]).all()

samples = [dict(png=np.zeros((400, 300, 3)))] * 10
batch = utils.samples_to_batch(samples)
assert batch["png"].shape == (10, 400, 300, 3)

import imp
imp.reload(utils)
samples = [dict(png=np.zeros((400, x, 3))) for x in [200, 100, 350, 150]]
batch = utils.samples_to_batch(samples, expand=True)
assert batch["png"].shape == (4, 400, 350, 3), batch["png"].shape



StarcoderdataJupyterScriptsDedupFiltered