Difference between keras Sequential and Functional API
Sr. No. | Sequential API | Functional API |
1 | Syntactical : Declared using keras.Sequential([]) function | Declared using keras.Model class |
2 | Syntactical : Addition of layers is by using .add interface or simply by using array like syntax | There 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 |
3 | Supports 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) |
4 | Supports only a single input layer | Supports multiple input layers |
5 | Supports only a single output layer | Supports multiple output layers |
6 | Supports 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 |
7 | Simplistic and non-flexible | Flexible and supports more complex scenarios |
8 | Easy to set-up and enough for most of the scenarios | Comparatively complex to set-up (if scenarios are complex) Beneficial as also only option for complex scenarios |
9 | Provides two prediction functons,
predict_proba outputs a numpy array of class probability predictions. Apart from these two it also supports the prediction functions
| Functional model does NOT provide the shortcuts predict_classes and predict_proba. It only provides the common prediction functions:
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