Book Image

Machine Learning with Swift

By : Jojo Moolayil, Alexander Sosnovshchenko, Oleksandr Baiev
Book Image

Machine Learning with Swift

By: Jojo Moolayil, Alexander Sosnovshchenko, Oleksandr Baiev

Overview of this book

Machine learning as a field promises to bring increased intelligence to the software by helping us learn and analyse information efficiently and discover certain patterns that humans cannot. This book will be your guide as you embark on an exciting journey in machine learning using the popular Swift language. We’ll start with machine learning basics in the first part of the book to develop a lasting intuition about fundamental machine learning concepts. We explore various supervised and unsupervised statistical learning techniques and how to implement them in Swift, while the third section walks you through deep learning techniques with the help of typical real-world cases. In the last section, we will dive into some hard core topics such as model compression, GPU acceleration and provide some recommendations to avoid common mistakes during machine learning application development. By the end of the book, you'll be able to develop intelligent applications written in Swift that can learn for themselves.
Table of Contents (18 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Calculating the size of a convolutional neural network


Let's take some well-known CNN, say VGG16, and see in detail how exactly the memory is being spent. You can print the summary of it using Keras:

from keras.applications import VGG16
model = VGG16()
print(model.summary())

The network consists of 13 2D-convolutional layers (with 3×3 filters, stride 1 and pad 1) and 3 fully connected layers ("Dense"). Plus, there are an input layer, 5 max-pooling layers and a flatten layer, which do not hold parameters.

Layer

Output shape

Data memory

Parameters

Number of parameters 

InputLayer

224×224×3

150528

0

0

Conv2D

224×224×64

3211264

3×3×3×64+64

1792

Conv2D

224×224×64

3211264

3×3×64×64+64

36928

MaxPool2D

112×112×64

802816

0

0

Conv2D

112×112×128

1605632

3×3×64×128+128

73856

Conv2D

112×112×128

1605632

3×3×128×128+128

147584

MaxPool2D

56×56×128

401408

0

0

Conv2D

56×56×256

802816

3×3×128×256+256

295168

Conv2D

56×56×256

802816

3×3×256×256+256

590080

Conv2D

56×56×256

802816

3×3×256×256+256

590080

MaxPool2D

28×28×256

200704

0

0

Conv2D

28×28×512

401408

3×3×256×512+512

1180160...