Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a High level Diagram for the architecture of the project and Detailed explanation of the algorithms/pre-trained models that you have used and construct

I need a High level Diagram for the architecture of the project and Detailed explanation of the algorithms/pre-trained models that you have used and construct a diagram for each one of them.:

import os import zipfile

# Download the CelebA dataset !wget -O celeba.zip https://www.dropbox.com/s/d1kjpkqklf0uw77/celeba.zip?dl=1

# Extract the images with zipfile.ZipFile("celeba.zip", "r") as zip_ref: zip_ref.extractall("celeba")

import numpy as np import pandas as pd from PIL import Image

# Load the attribute labels attributes = pd.read_csv("celeba/list_attr_celeba.csv")

# Select only the "Image_ID" and "Smiling" columns attributes = attributes[["Image_ID", "Smiling"]]

# Convert the "Smiling" column to a boolean attributes["Smiling"] = (attributes["Smiling"] == 1)

# Create an empty list to store the images images = []

# Load the images and resize them to 128x128 for i, row in attributes.iterrows(): image_id = row["Image_ID"] image = Image.open(f"celeba/{image_id}") image = image.resize((128, 128)) image = np.array(image) images.append(image)

# Convert the images to a numpy array images = np.array(images)

# Split the images into a training set and a validation set train_images = images[:100000] val_images = images[100000:]

# Split the attribute labels into a training set and a validation set train_attributes = attributes[:100000] val_attributes = attributes[100000:]

import tensorflow as tf import tensorflow_gan as tfgan

# Load the dataset (train_images, train_attributes), (val_images, val_attributes) = load_celeba_dataset(num_images=100000)

# Create the generator and discriminator models generator = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(128, 128, 3)), tf.keras.layers.Conv2D(filters=64, kernel_size=3, strides=1, padding="same", activation="relu"), tf.keras.layers.Conv2D(filters=128, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2D(filters=256, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2D(filters=512, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2DTranspose(filters=256, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2DTranspose(filters=128, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2DTranspose(filters=64, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Conv2DTranspose(filters=3, kernel_size=3, strides=1, padding="same", activation="tanh"), ])

discriminator = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(128, 128, 3)), tf.keras.layers.Conv2D(filters=64, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Dropout(0.5), tf.keras.layers.Conv2D(filters=128, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Dropout(0.5), tf.keras.layers.Conv2D(filters=256, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Dropout(0.5), tf.keras.layers.Conv2D(filters=512, kernel_size=3, strides=2, padding="same", activation="relu"), tf.keras.layers.Dropout(0.5), tf.keras.layers.Flatten(), tf.keras.layers.Dense(1, activation="sigmoid"), ])

# Compile the generator model generator.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=2e-4, beta_1=0.5), loss="binary_crossentropy")

# Compile the discriminator model discriminator.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=2e-4, beta_1=0.5), loss="binary_crossentropy", metrics=["accuracy"])

# Create the GAN model gan = tfgan.gan_model(generator, discriminator) gan.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=2e-4, beta_1=0.5), loss="binary_crossentropy")

# Train the GAN model gan.fit(train_images, epochs=20, batch_size=64, validation_data=(val_images, val_attributes))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

LOQ 14-19: What criticisms have social-cognitive theories faced?

Answered: 1 week ago