Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Keras Deep Learning Cookbook

You're reading from  Keras Deep Learning Cookbook

Product type Book
Published in Oct 2018
Publisher Packt
ISBN-13 9781788621755
Pages 252 pages
Edition 1st Edition
Languages
Authors (3):
Rajdeep Dua Rajdeep Dua
Profile icon Rajdeep Dua
Sujit Pal Sujit Pal
Profile icon Sujit Pal
Manpreet Singh Ghotra Manpreet Singh Ghotra
Profile icon Manpreet Singh Ghotra
View More author details
Toc

Table of Contents (17) Chapters close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Keras Installation 2. Working with Keras Datasets and Models 3. Data Preprocessing, Optimization, and Visualization 4. Classification Using Different Keras Layers 5. Implementing Convolutional Neural Networks 6. Generative Adversarial Networks 7. Recurrent Neural Networks 8. Natural Language Processing Using Keras Models 9. Text Summarization Using Keras Models 10. Reinforcement Learning 1. Other Books You May Enjoy Index

Keras functional APIs


Keras functional APIs provide each layer as a function.

How to do it...

  1. To use the functional APIs, you need to import the following classes from the keras package:
from keras.layers.core import dense, Activation
  1. Let's use the preceding imported layers as part of the Sequential model:
from keras.models import Sequential
from keras.layers.core import dense, Activation
model = Sequential([
  dense(32, input_dim=784),
  Activation("sigmoid"),
  dense(10),
  Activation("softmax"),
])
model.compile(loss="categorical_crossentropy", optimizer="adam")
  1. Let's run the previous functional API-based model on MNIST:
from keras.utils import plot_model
from keras.layers import Flatten
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.datasets import mnist
import keras

num_classes = 10
batch_size = 32
epochs = 10
batch_size = 128
num_classes = 10
epochs = 12

# input image dimensions
img_rows, img_cols = 28, 28

# the data, split between train...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime