Skip to content

Instantly share code, notes, and snippets.

@rohan-paul
Last active September 16, 2021 11:27
Show Gist options
  • Select an option

  • Save rohan-paul/76f03bdd79519ae2daee051d4acf649c to your computer and use it in GitHub Desktop.

Select an option

Save rohan-paul/76f03bdd79519ae2daee051d4acf649c to your computer and use it in GitHub Desktop.
import warnings
warnings.filterwarnings('ignore')
import glob
import numpy as np # linear algebra
import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
import os
from tensorflow.keras import preprocessing
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D,Dropout,Dense,Flatten,Conv2DTranspose,BatchNormalization,LeakyReLU,Reshape
import tensorflow as tf
from tensorflow.keras.utils import plot_model
all_image_path = []
full_image_train_path = '../input/celeba-dataset/img_align_celeba/img_align_celeba'
# Now from this array
for path in os.listdir(full_image_train_path):
if '.jpg' in path:
all_image_path.append(os.path.join(full_image_train_path, path))
image_path_50k = all_image_path[0:50000]
# Model Constants
PLOTS_DPI = 150
# Cropping
cropping_box = (30, 55, 150, 175)
# To load an image from a file, we use the open() function in the Image module, passing it the path to the image.
training_images = [np.array((Image.open(path).crop(cropping_box)).resize((64,64))) for path in image_path_50k]
# Normalizing images to range in 0-1
for i in range(len(training_images)):
training_images[i] = ((training_images[i] - training_images[i].min())/(255 - training_images[i].min()))
training_images = np.array(training_images)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment