Skip to main content

Tensorflow/Keras Model Profiler: Tells you model's memory requirement, no. of parameters, flops etc.

Project description

License: MIT Keras TensorFlow

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

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 VGG16

model = VGG16(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                     | 0.30932349055999997 | BFLOPs  |
| GPU Memory Requirement           | 7.4066760912537575  | GB      |
| Model Parameters                 | 138.357544          | Million |
| Memory Required by Model Weights | 527.7921447753906   | MB      |

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model_profiler-0.1.7.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

model_profiler-0.1.7-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file model_profiler-0.1.7.tar.gz.

File metadata

  • Download URL: model_profiler-0.1.7.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6

File hashes

Hashes for model_profiler-0.1.7.tar.gz
Algorithm Hash digest
SHA256 59f20767c030ea6b3799467b6678e009cb12eb1657cc0fdf90e2b53695211f1d
MD5 f4b9fb41e2f83569cb4a9b01e3788cbb
BLAKE2b-256 2bb5b6e2739c410d321afd12bbe89b6e32ecce274b1f74ccdf1c3ff6784c1fae

See more details on using hashes here.

File details

Details for the file model_profiler-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: model_profiler-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6

File hashes

Hashes for model_profiler-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e3bcbb0f99c3065a2ac435493731906e03f8fe230bf017b94c49dd7e26da5552
MD5 a15ce7dbba6a0b3d3d166ae113228cde
BLAKE2b-256 c5362afe2e49b0002c6c569a9e7f1fa25363efbbb30f48bcb2f25e1a0dd54c2d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page