In [ ]:
from pathlib import Path
HOME = Path.home()

In [ ]:
import matplotlib.pyplot as plt

In [ ]:
# Load the model:
from unsupervised_models.cvae import ConvolutionalVariationalAutoencoder

IM_SIZE = 64
vae = ConvolutionalVariationalAutoencoder(image_dims=(IM_SIZE, IM_SIZE, 3))
vae.load_weights(HOME / "vae_models/weights.49.hdf5")

In [ ]:
color_map = {
    "bright_blue": 'b',
    "bright_red": "r",
    "bright_violet": "m",
    "bright_yellow": "y",
    "dark_green": "g",
    "light_pink": "c",
    # white is black for now
    "white": "k"
}

def colors_from_directory(directory):
    return list(filter(None, (color_map.get(os.path.basename(root), None) for root, _, files in os.walk(directory) for _ in files)))

In [ ]:
DATA_DIR = HOME / "Img/train"
# DATA_DIR = HOME / "Img/validate"

In [ ]:
from duckdata.blender import read_normalized, img_paths
training_data = np.stack(list(map(read_normalized, img_paths(DATA_DIR))), axis=0)

In [ ]:
preds = vae.encoder.predict(training_data)

In [ ]:
preds[1]

In [ ]:
fig = plt.figure(figsize=(15, 15))
plt.scatter(preds[:, 0], preds[:, 1], color=colors_from_directory(DATA_DIR))
# ax.set_facecolor('red')
plt.show()

In [ ]:
import numpy as np

In [ ]:
t = vae.generator.predict(np.array([[0.32,  0.15666]]))

plt.imshow(t[0])
plt.show()

In [ ]:
from scipy import misc, ndimage

In [ ]:
im = misc.imread(DATA_DIR / "bright_yellow/target.png")

In [ ]:
plt.imshow(im)
plt.show()

In [ ]:
plt.imshow(ndimage.uniform_filter(im, size=2))
plt.show()

In [ ]:
from skimage import restoration
plt.imshow(restoration.denoise_tv_chambolle(im))
plt.show()

In [ ]: