# coding: utf-8 # ### Generating human faces with Adversarial Networks import sys sys.path.append("..") import helpers helpers.mask_busy_gpus(wait=False) import numpy as np #Those attributes will be required for the final part of the assignment (applying smiles), so please keep them in mind #from lfw_dataset2 import load_lfw_dataset from lfw_dataset import load_lfw_dataset data, attrs = load_lfw_dataset(dimx=36, dimy=36) #data = load_lfw_dataset(use_raw=True,dimx=36,dimy=36) #print(np.max(data),np.min(data)) #preprocess faces #data = np.float32(data) #print(data[0]) data = (data - 127.5) / float(127.5) #scale to between -1 and 1 #print(data[0]) IMG_SHAPE = data.shape[1:] # In[3]: #print random image print(data.shape) import tensorflow as tf gpu_options = tf.GPUOptions(allow_growth=True, per_process_gpu_memory_fraction=0.333)
from keras_utils import reset_tf_session # !!! remember to clear session/graph if you rebuild your graph to avoid out-of-memory errors !!! """# Load dataset Dataset was downloaded for you. Relevant links (just in case): - http://www.cs.columbia.edu/CAVE/databases/pubfig/download/lfw_attributes.txt - http://vis-www.cs.umass.edu/lfw/lfw-deepfunneled.tgz - http://vis-www.cs.umass.edu/lfw/lfw.tgz """ # we downloaded them for you, just link them here download_utils.link_week_4_resources() # load images X, attr = load_lfw_dataset(use_raw=True, dimx=32, dimy=32) IMG_SHAPE = X.shape[1:] # center images X = X.astype('float32') / 255.0 - 0.5 # split X_train, X_test = train_test_split(X, test_size=0.1, random_state=42) def show_image(x): plt.imshow(np.clip(x + 0.5, 0, 1)) plt.title('sample images') for i in range(6): plt.subplot(2,3,i+1)