Calculating the Number of flops for a given Neural Network?
There is no such code because the quantity of FLOPs is dependent on the hardware and software implementations.  You can certainly derive a typical quantity from expanding the layer-by-layer operations for each parameter and weight. and making reasonable implementation assumptions for each activation function.
Input dimensions will proportionately affect the computations for the first layer.
I'm not sure what you intend for "generalized code in Python"; do you envision using a form of the Keras model as the input?  This is possible, but you need to write modules that will extract the kernel characteristics and connection logic from the Keras representation.
Your quantity of operations will vary from one implementation to another.  Hardware architectures now directly support parallel operations and short-cuts for sparse matrices.  Some have extra functionality for adjusting floating-point representations for greater training speed.  Software platforms include control and data flow analysis to optimize the functional flow.  Any of these will change the FLOPs computation.
I have a neural network(ALEXnet or VGG16) written with Keras for Image Classification and I would like to calculate the Number of floating point operations for a network. The size of the images in the dataset could varry.
Can a generlized code be written in python which could calculate flops automatically ? or is there any libraray avaialble.
I am working with spyderAnaconda and the defined network is a sequential model.
Thank you.