Advanced Deep Learning with Keras

fourpersent2020
from fourpersent2020 More from this publisher
16.03.2021 Views

def encoder_layer(inputs,filters=16,kernel_size=3,strides=2,activation='relu',instance_norm=True):"""Builds a generic encoder layer made of Conv2D-IN-LeakyReLUIN is optional, LeakyReLU may be replaced by ReLU"""conv = Conv2D(filters=filters,kernel_size=kernel_size,strides=strides,padding='same')x = inputsif instance_norm:x = InstanceNormalization()(x)if activation == 'relu':x = Activation('relu')(x)else:x = LeakyReLU(alpha=0.2)(x)x = conv(x)return xWhenever possible, docstring is included. At the very least, text comment is usedto minimize space usage.Any command-line code execution is written as follows:$ python3 dcgan-mnist-4.2.1.pyPrefaceThe example code file naming is: algorithm-dataset-chapter.section.number.py. The command-line example is DCGAN on MNIST dataset in Chapter 4, secondsection and first listing. In some cases, the explicit command line to execute is notwritten but it is assumed to be:$ python3 name-of-the-file-in-listingThe file name of the code example is included in the Listing caption.[ ix ]

PrefaceGet in touchFeedback from our readers is always welcome.General feedback: Email feedback@packtpub.com, and mention the book's titlein the subject of your message. If you have questions about any aspect of this book,please email us at questions@packtpub.com.Errata: Although we have taken every care to ensure the accuracy of our content,mistakes do happen. If you have found a mistake in this book we would be gratefulif you would report this to us. Please visit, http://www.packtpub.com/submiterrata,selecting your book, clicking on the Errata Submission Form link, andentering the details.Piracy: If you come across any illegal copies of our works in any form on theInternet, we would be grateful if you would provide us with the location addressor website name. Please contact us at copyright@packtpub.com with a link to thematerial.If you are interested in becoming an author: If there is a topic that you haveexpertise in and you are interested in either writing or contributing to a book,please visit http://authors.packtpub.com.ReviewsPlease leave a review. Once you have read and used this book, why not leavea review on the site that you purchased it from? Potential readers can then see anduse your unbiased opinion to make purchase decisions, we at Packt can understandwhat you think about our products, and our authors can see your feedback on theirbook. Thank you!For more information about Packt, please visit packtpub.com.[ x ]

def encoder_layer(inputs,

filters=16,

kernel_size=3,

strides=2,

activation='relu',

instance_norm=True):

"""Builds a generic encoder layer made of Conv2D-IN-LeakyReLU

IN is optional, LeakyReLU may be replaced by ReLU

"""

conv = Conv2D(filters=filters,

kernel_size=kernel_size,

strides=strides,

padding='same')

x = inputs

if instance_norm:

x = InstanceNormalization()(x)

if activation == 'relu':

x = Activation('relu')(x)

else:

x = LeakyReLU(alpha=0.2)(x)

x = conv(x)

return x

Whenever possible, docstring is included. At the very least, text comment is used

to minimize space usage.

Any command-line code execution is written as follows:

$ python3 dcgan-mnist-4.2.1.py

Preface

The example code file naming is: algorithm-dataset-chapter.section.number.

py. The command-line example is DCGAN on MNIST dataset in Chapter 4, second

section and first listing. In some cases, the explicit command line to execute is not

written but it is assumed to be:

$ python3 name-of-the-file-in-listing

The file name of the code example is included in the Listing caption.

[ ix ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!