Exemple #1
0
import utils.start_tf
from utils.start_tf import *
from utils.start_tf import _TAGS
from utils.test_dir import save_make_dir
import config

source_dir = config.data_path / 'test'
save_make_dir(source_dir)

def test():
    img = Image.open(source_dir / 'img.png')
    img = np.reshape(np.array(img), [1, 256, 256, 3])

    # Encoding speed
    print('encoding')
    t = time.time()
    eps = encode(img)
    for _ in tqdm(range(10)):
        eps = encode(img)
    print("Encoding latency {} sec/img".format((time.time() - t) / (1*10)))

    # Decoding speed
    print('decoding')
    t = time.time()
    dec = decode(eps)
    for _ in tqdm(range(10)):
        dec = decode(eps)
    print("Decoding latency {} sec/img".format((time.time() - t) / (1*10)))
    img = Image.fromarray(dec[0])
    img.save(source_dir / 'dec.png')
Exemple #2
0
# Input: img_path
# Output: aligned_img if face_found, else None
def align(img_path):
    img = Image.open(img_path)
    img = img.convert('RGB')  # if image is RGBA or Grayscale etc
    img = np.array(img)
    x, face_found = align_face(img)
    return x


if __name__ == '__main__':
    index_path = args.index
    input_path = args.input_path
    output_path = args.output_path

    save_make_dir(input_path)
    save_make_dir(output_path)

    with open(index_path) as fp:

        # The first two are use less
        line = fp.readline()
        line = fp.readline()

        t_0 = time()

        while line:
            line = fp.readline()
            line = line.split()
            file = line[0]
Exemple #3
0
import utils.glow_api as glow_api
from utils.test_dir import save_make_dir
from utils.get_celeba_info import get_celeba_index
from numpy import linalg as LA
import pickle

source_dir = '../data/celeba/img/'
result_dir = '../data/celeba/results/random_distances/'
save_make_dir(result_dir)

celeb_index = get_celeba_index()

# We generate global distance distribution
distances = list()
for n in range(1000):
    print(n)
    file_name_1, file_name_2 = celeb_index.sample(n=2)['img_id'].values

    eps_1 = glow_api.load_encode(source_dir, file_name_1)
    eps_2 = glow_api.load_encode(source_dir, file_name_2)

    distances.append(LA.norm(eps_1 - eps_2))

with open(result_dir + 'global_distances.pickle', 'wb') as handle:
    pickle.dump(distances, handle, protocol=pickle.HIGHEST_PROTOCOL)

print('done')
# This script is produced to see if the average of all points in the latent space is zero
from glob import glob
import numpy as np
from tqdm import tqdm
import platform
import config
from utils.test_dir import save_make_dir
import os
from utils.FileNPAbstraction import fnpa

os.nice(0)


np_path = config.data_path / 'np_test'
re_path = config.results_path / 'linear_analysis_test_no_block'
save_make_dir(re_path)

file_num = 0
the_average = None

cwd = os.getcwd()
os.chdir(np_path)
file_list = os.listdir()
file_list.sort()
os.chdir(cwd)

for file in tqdm(file_list):
    # an_np = np.load(np_path / file)
    an_np = fnpa.get_np(file)
    an_np = an_np.copy()
    file_num += 1
Exemple #5
0
import utils.start_tf
from utils.start_tf import *
import glow_api
from utils.test_dir import save_make_dir
import glob
from tqdm import tqdm
import os

source_dir = '../data/celeba_wild/data_256_fast/'
#source_dir = '../data/test/'
target_dir = '../data/celeba_wild/np/'
save_make_dir(target_dir)


def convert_img_2_np():
    cwd = os.getcwd()
    os.chdir(source_dir)
    aux = list(glob.glob('*'))
    os.chdir(cwd)

    for img_file in tqdm(aux):
        if not os.path.exists(target_dir + img_file[:-4] + '.npy'):
            eps = glow_api.load_encode(source_dir, img_file)
            np.save(target_dir + img_file[:-4] + '.npy', eps)


if __name__ == '__main__':
    print('converting')
    convert_img_2_np()
    print('done')
Exemple #6
0
import utils.start_tf
from utils.start_tf import *
from utils.test_dir import save_make_dir

source_dir = '../data/celeba/img/'
result_dir = '../data/celeba/results/components_transition/'

save_make_dir(source_dir)
save_make_dir(result_dir)


def test_drop_components_1_1_transition():
    from PIL import Image
    from numpy import linalg as LA

    # Modifications
    # 195309
    # 194582
    # 192426
    # 120327

    # People
    # 082099
    # 032080

    peoples = ['082099', '032080']
    components = [195309, 194582, 192426, 120327]

    for p in peoples:
        print(p)
        img_eg = Image.open(source_dir + p + '.jpg')