Skip to content

Commit 914a93e

Browse files
instructions
1 parent e68f500 commit 914a93e

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Tensorflow/ Keras Model Profiler
2+
3+
Gives you some basic but important information about your `tf` or `keras` model like,
4+
5+
* Model Parameters
6+
* Model memory requirement on GPU
7+
* Memory required to store parameters `model weights`.
8+
* GPU availability and GPU IDs if available
9+
10+
## Dependencies
11+
12+
```
13+
python 3
14+
numpy
15+
tabulate
16+
tensorflow >= 2.0.0
17+
keras >= 2.2.4
18+
```
19+
Built and tested on `tensorflow == 2.3.1`
20+
21+
## Installation
22+
23+
```
24+
pip install model_profiler
25+
```
26+
27+
## Usage
28+
29+
Firs load any model built using keras or tensorflow. Here for simplicity we will load model from kera applications.
30+
31+
```python
32+
form tensorflow.keras.applications import VGG16
33+
34+
model = VGG16(include_top=True, weights="imagenet", input_tensor=None,
35+
input_shape=None, pooling=None, classes=1000,
36+
classifier_activation="softmax")
37+
```
38+
39+
Now after installing `model_profiler` run
40+
41+
```python
42+
from profiler import model_profiler
43+
44+
Batch_size = 128
45+
profile = model_profiler(model, Batch_size)
46+
```
47+
`Batch_size` have effect on `model` memory usage so GPU memory usage need `batch_size`, it's default value if `1`.
48+
49+
### Output
50+
51+
```
52+
| Model Profile | Value | Unit |
53+
|----------------------------------|---------------------|---------|
54+
| Selected GPUs | ['0', '1'] | GPU IDs |
55+
| No. of FLOPs | 0.30932349055999997 | BFLOPs |
56+
| GPU Memory Requirement | 7.4066760912537575 | GB |
57+
| Model Parameters | 138.357544 | Million |
58+
| Memory Required by Model Weights | 527.7921447753906 | MB |
59+
```
60+
Default units for the prfiler are
61+
62+
```
63+
# in order
64+
use_units = ['GPU IDs', 'BFLOPs', 'GB', 'Million', 'MB']
65+
66+
```
67+
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.
68+
69+
```
70+
# keep order
71+
use_units = ['GPU IDs', 'MFLOPs', 'GB', 'Million', 'MB']
72+
```
73+
### Availabel units are
74+
```
75+
'GB':memory unit gega-byte
76+
'MB': memory unit mega-byte
77+
'MFLOPs': FLOPs unit million-flops
78+
'BFLOPs': FLOPs unit billion-flops
79+
'Million': paprmeter count unit millions
80+
'Billion': paprmeter count unit billions
81+
82+
```
83+
## More Examples
84+
85+
For further details and more examples visit my [github](https://github.com/Mr-TalhaIlyas/Tensorflow-Keras-Model-Profiler)

0 commit comments

Comments
 (0)