3 Ways to build a Keras Model

Photo by Michael Fousert on Unsplash

The scope of this story is to build a Keras model using different ways: the sequential model, the functional model, and a custom model via sub-classing.

The sequential model:

First, building a model by passing a list of layers to it.

Or by adding layers via add method.

This approach only works when you have a single input and a single output.

The functional API:

Second, this approach adds arguments using parentheses; for example, the function f(x, y) becomes f(x)(y). This style is called currying in functional programming.

This approach allows for creating complex models with: multiple inputs, auxiliary outputs, and non-sequential paths.

A custom model via sub-classing:

Finally, this approach is for research use. It allows researchers to create complex models such as: adding custom layers, skipping connections, etc.

Albeit, when it comes to serialization, this approach requires additional work.

Programming and Statistics for now!