Tensorflow/ Keras Model Profiler
Gives you some basic but important information about your tf or keras model like,
- Model Parameters
- Model memory requirement on GPU
- Memory required to store parameters
model weights. - GPU availability and GPU IDs if available
Version 1.1.8 fixes problems with custom sequential models and includes other minor improvements.
Dependencies
python >= 3.6
numpy
tabulate
tensorflow >= 2.0.0
keras >= 2.2.4
Built and tested on tensorflow >= 2.3.1
Installation
using pip.
pip install model_profiler
Usage
Firs load any model built using keras or tensorflow. Here for simplicity we will load model from kera applications.
from tensorflow.keras.applications import EfficientNetB3
model = EfficientNetB3(include_top=True)
Now after installing model_profiler run
from model_profiler import model_profiler
Batch_size = 128
profile = model_profiler(model, Batch_size)
print(profile)
Batch_size have effect on model memory usage so GPU memory usage need batch_size, it's default value if 1.
Output
| Model Profile | Value | Unit |
|----------------------------------|---------------|---------|
| Selected GPUs | ['0', '1'] | GPU IDs |
| No. of FLOPs | 1.5651 | BFLOPs |
| GPU Memory Requirement | 41.7385 | GB |
| Model Parameters | 12.3205 | Million |
| Memory Required by Model Weights | 46.9991 | MB |
Using Custom Models
you can also built your own models on top of keras.application a simple example is given below. The usage is almost same the only difference is that for better calculation of FLOPs, it's better to
sepcify the input_shape argument. Simple example below.
from tensorflow.keras.applications import EfficientNetB3
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from profiler import model_profiler
custom_model = Sequential()
custom_model.add(EfficientNetB3(weights='imagenet', include_top=False,
input_shape=(296,256,3), pooling='avg'))
# build you custom layers on top
custom_model.add(Dropout(0.50))
custom_model.add(Dense(1000, activation='softmax'))
profile = model_profiler(custom_model, Batch_size)
Output
| Model Profile | Value | Unit |
|----------------------------------|---------------|---------|
| Selected GPUs | None Detected | GPU IDs |
| No. of FLOPs | 1.2868 | BFLOPs |
| GPU Memory Requirement | 34.8656 | GB |
| Model Parameters | 10.7989 | Million |
| Memory Required by Model Weights | 41.1945 | MB |
Units
Default units for the prfiler are
# in order
use_units = ['GPU IDs', 'BFLOPs', 'GB', 'Million', 'MB']
You can change units by changing the list entry in appropriate location. For example if you want to get model FLOPs in million just change the list as follows.
# keep order
use_units = ['GPU IDs', 'MFLOPs', 'GB', 'Million', 'MB']
Availabel units are
'GB':memory unit gega-byte
'MB': memory unit mega-byte
'MFLOPs': FLOPs unit million-flops
'BFLOPs': FLOPs unit billion-flops
'Million': paprmeter count unit millions
'Billion': paprmeter count unit billions
More Examples
For further details and more examples visit my github
Metadata
Release files for model-profiler 1.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| model_profiler-1.1.8.tar.gz | 6.9 kB | Without provenance | Details for model_profiler-1.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| model_profiler-1.1.8-py3-none-any.whl | Python 3 | none | any | Details for model_profiler-1.1.8-py3-none-any.whl |
Total release size: 13.2 kB
Release files / model_profiler-1.1.8.tar.gz
| Download URL | model_profiler-1.1.8.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bb682849150bb9306353f15fb6b9bc3598fa382deaecfe6a1f7b16a585b806d
|
|
BLAKE2b-256 checksum How to use checksums |
71c9947592f8ab32095ca6baa28837727c13572dce32f68a23127495607c5835
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / model_profiler-1.1.8-py3-none-any.whl
| Download URL | model_profiler-1.1.8-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06a64693b3951b52737c91839cd9399344450895afeb86cae3683c0e18ae4926
|
|
BLAKE2b-256 checksum How to use checksums |
77dd26702f220aca6457fb14c36f0e6d4965d97b9102fd1e291f1ad2dac61a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for model-profiler 1.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.