Skip to main content

keras-flops

PyPI version

FLOPs calculator for neural network architecture written in tensorflow (tf.keras) v2.2+

This stands on the shoulders of giants, tf.profiler.

Requirements

  • Python 3.6+
  • Tensorflow 2.2+

Installation

Using pip:

pip install keras-flops

Example

See colab examples here in details.

from tensorflow.keras import Model, Input
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout

from keras_flops import get_flops

# build model
inp = Input((32, 32, 3))
x = Conv2D(32, kernel_size=(3, 3), activation="relu")(inp)
x = Conv2D(64, (3, 3), activation="relu")(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Dropout(0.25)(x)
x = Flatten()(x)
x = Dense(128, activation="relu")(x)
x = Dropout(0.5)(x)
out = Dense(10, activation="softmax")(x)
model = Model(inp, out)

# Calculae FLOPS
flops = get_flops(model, batch_size=1)
print(f"FLOPS: {flops / 10 ** 9:.03} G")
# >>> FLOPS: 0.0338 G

Support

Support tf.keras.layers as follows,

name layer
Conv Conv[1D/2D/3D]
Conv[1D/2D]Transpose
DepthwiseConv2D
SeparableConv[1D/2D]
Pooling AveragePooling[1D/2D]
GlobalAveragePooling[1D/2D/3D]
MaxPooling[1D/2D]
GlobalMaxPool[1D/2D/3D]
Normalization BatchNormalization
Activation Softmax
Attention Attention
AdditiveAttention
others Dense

Not supported

Not support tf.keras.layers as follows. They are calculated as zero or smaller value than correct value.

name layer
Conv Conv3DTranspose
Pooling AveragePooling3D
MaxPooling3D
UpSampling[1D/2D/3D]
Normalization LayerNormalization
RNN SimpleRNN
LSTM
GRU
others Embedding

Metadata

Release files for keras-flops 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-flops 0.1.2
File Size Uploaded
keras-flops-0.1.2.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-flops 0.1.2
File Interpreter ABI Platform
keras_flops-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / keras-flops-0.1.2.tar.gz

Download URL keras-flops-0.1.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2561043d435dce3b0b6a68573a538facddbcfa637faf7ae7f48b2e8f373ed84e
BLAKE2b-256 checksum
How to use checksums
65d4bc5aeafede12dd7e31b71653349d791e31610e6d5859fce556599f8af91e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.8 CPython/3.6.10 Linux/4.19.84-microsoft-standard

Release files / keras_flops-0.1.2-py3-none-any.whl

Download URL keras_flops-0.1.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1202bb610f82a931ed65964fb9c330875001a5b1d527b279062185178541366a
BLAKE2b-256 checksum
How to use checksums
bc77e384f6e427e1920624a9229b411010eaa244134cff6a230d303d3b1ea0be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.8 CPython/3.6.10 Linux/4.19.84-microsoft-standard

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page