QuestionQuestion

Transcribed TextTranscribed Text

HW3 ● Train a discriminator/generator pair on CIFAR10 dataset utilizing techniques from DCGAN and Wasserstein GANs Baseline Model for DCGAN ● Generator β—‹ noise_input = (100,); β—‹ text_input = (119,); β—‹ # num of (hair, eyes) pairs β—‹ text_emb = Dense(256,β€˜relu’)(text_input); β—‹ concatenate([noise_input, text_emb]); β—‹ Dense(4*4*512); Reshape((4, 4, 512)); β—‹ Batchnorm(mom=0.9); Relu; β—‹ Conv2DTranspose(256, kernel=5); β—‹ Batchnorm(mom=0.9); Relu; β—‹ Conv2DTranspose(128, kernel=5); β—‹ Batchnorm(mom=0.9); Relu; β—‹ Conv2DTranspose(64, kernel=5); β—‹ Batchnorm(mom=0.9); Relu; β—‹ Conv2DTranspose(3, kernel=5); β—‹ Tanh; ● Discriminator β—‹ image_input = (64,64,3); β—‹ text_input = (119,); β—‹ text_emb = Dense(256,’relu’)(text_input); β—‹ text_emb = Reshape((1,1,256))(text_emb); β—‹ tiled_emb = tile(text_emb, [1,4,4,1]); β—‹ Conv2D(64 ,kernel=5)(image_input); LeakyRelu; β—‹ Conv2D(128, kernel=5); β—‹ Batchnorm(mom=0.9); LeakyRelu; β—‹ Conv2D(256, kernel=5); β—‹ Batchnorm(mom=0.9); LeakyReLu; β—‹ Conv2D(512, kernel=5); β—‹ Batchnorm(mom=0.9); β—‹ image_feat = LeakyRelu; β—‹ concatenate([image_feat, tiled_emb]); β—‹ Conv2D(512, kernel=1, strides=(1,1)); β—‹ Flatten; β—‹ Dense(1, β€˜sigmoid’); ● Training β—‹ Adam(lr = 0.0002, beta = 0.5)

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

rom math import floor
from numpy import ones
from numpy import expand_dims
from numpy import log
from numpy import mean
from numpy import std
from numpy import exp
from numpy.random import shuffle
from keras.applications.inception_v3 import InceptionV3
from keras.applications.inception_v3 import preprocess_input
from keras.datasets import cifar10
from skimage.transform import resize
from numpy import asarray

# scale an array of images to a new size
def scale_images(images, new_shape):
images_list = list()
for image in images:
# resize with nearest neighbor interpolation
new_image = resize(image, new_shape, 0)
# store
images_list.append(new_image)
return asarray(images_list)

# assumes images have any shape and pixels in [0,255]
def calculate_inception_score(images, n_split=10, eps=1E-16):
# load inception v3 model
model = load('gen_model_020.h5')
# enumerate splits of images/predictions
scores = list()
n_part = floor(images.shape[0] / n_split)
for i in range(n_split):
# retrieve images
ix_start, ix_end = i * n_part, (i+1) * n_part
subset = images[ix_start:ix_end]
# convert from uint8 to float32
subset = subset.astype('float32')
# scale images to the required size
subset = scale_images(subset, (299,299,3))
# pre-process images, scale to [-1,1]
subset = preprocess_input(subset)
# predict p(y|x)
p_yx = model.predict(subset)
# calculate p(y)
p_y = expand_dims(p_yx.mean(axis=0), 0)
# calculate KL divergence using log probabilities
kl_d = p_yx * (log(p_yx + eps) - log(p_y + eps))
# sum over classes
sum_kl_d = kl_d.sum(axis=1)
# average over images
avg_kl_d = mean(sum_kl_d)
# undo the log
is_score = exp(avg_kl_d)
# store
scores.append(is_score)
# average across images
is_avg, is_std = mean(scores), std(scores)
return is_avg, is_std

# load cifar10 images
(images, _), (_, _) = cifar10.load_data()
# shuffle images
shuffle(images)...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$210.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Artificial Intelligence Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats