Thursday, May 13, 2021

 

Difference between keras Sequential and Functional API


Sr. No.Sequential APIFunctional API
1Syntactical : Declared using keras.Sequential([]) functionDeclared using keras.Model class 
2Syntactical : Addition of layers is by using .add interface or simply by using array like syntaxThere is no addition of layers, you simply declare the model's input and output layers. If there are more layers required in between, they have to be added to input layer using functional syntax
3Supports only linear graphs of layers (that means branching is not supported)Supports non-linear graphs of layers (that means layers can branch out and merge)
4Supports only a single input layerSupports multiple input layers
5Supports only a single output layerSupports multiple output layers
6Supports no sharing of layers (it is not needed also since layer can communicate only to one input and one output layer)Layers can be shared across other layers down the chain
7Simplistic and non-flexibleFlexible and supports more complex scenarios
8Easy to set-up and enough for most of the scenariosComparatively complex to set-up (if scenarios are complex)
Beneficial as also only option for complex scenarios
9Provides two prediction functons,
  • predict_classes
  • predict_proba. 
predict_classes outputs a numpy array of class predictions.
predict_proba outputs a numpy array of class probability predictions. 

Apart from these two it also supports the prediction functions
  • predict,
  • predict_on_batches
  • predict_step
Functional model does NOT provide the shortcuts predict_classes and predict_proba. 

It only provides the common prediction functions:
  • predict,
  • predict_on_batches
  • predict_step

Note 1: Both Sequential and Functional models earlier supported a method called predict_generator, to be used with generators. However, this method is now deprecated and the functionality is merged with predict function.
Note 2: predict_classes and predict_proba (which are supported by Sequential model only) only make sense in case of classification problems. 


No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...