|
2 | 2 | """
|
3 | 3 | Profiles the conversion of a Keras model.
|
4 | 4 | """
|
5 |
| -import cProfile, pstats, io |
| 5 | +import sys |
| 6 | +import cProfile |
| 7 | +import pstats |
6 | 8 | from pstats import SortKey
|
7 |
| -import fire |
| 9 | +import io |
| 10 | +import argparse |
8 | 11 | import tensorflow as tf
|
9 | 12 | from tf2onnx import tfonnx
|
10 | 13 | from tensorflow.keras.applications import MobileNet, EfficientNetB2
|
@@ -62,7 +65,7 @@ def profile(profiler="none", name="MobileNet", show_all=False):
|
62 | 65 |
|
63 | 66 | :param profiler: one among none, spy, pyinstrument, cProfile
|
64 | 67 | :param name: model to profile, MobileNet, EfficientNetB2
|
65 |
| - :param show_all: use by pyinstrument to show all functions |
| 68 | + :param showall: used by pyinstrument to show all functions |
66 | 69 | """
|
67 | 70 | print("create(%r, %r)" % (profiler, name))
|
68 | 71 | graph_def, model = create(name)
|
@@ -94,6 +97,21 @@ def profile(profiler="none", name="MobileNet", show_all=False):
|
94 | 97 | raise ValueError("Unknown profiler %r." % profiler)
|
95 | 98 |
|
96 | 99 |
|
| 100 | +def main(args): |
| 101 | + parser = argparse.ArgumentParser(description='Process some integers.') |
| 102 | + parser.add_argument('--profiler', default='none', |
| 103 | + choices=['none', 'spy', 'pyinstrument', 'cProfile'], |
| 104 | + help='a profiler') |
| 105 | + parser.add_argument('--name', default="MobileNet", |
| 106 | + choices=['MobileNet', 'EfficientNetB2'], |
| 107 | + help="a model") |
| 108 | + parser.add_argument('--showall', type=bool, default=False, |
| 109 | + help="used by pyinstrument to show all functions") |
| 110 | + res = parser.parse_args(args) |
| 111 | + profile(res.profiler, res.name, res.showall) |
| 112 | + |
| 113 | + |
97 | 114 | if __name__ == '__main__':
|
98 |
| - fire.Fire(profile) |
| 115 | + print('Begin Profile with', sys.argv[1:]) |
| 116 | + main(sys.argv[1:]) |
99 | 117 | print('Profile complete.')
|
0 commit comments