Skip to content

Commit

Permalink
add profile option for frontend profiling to image script (apache#8171)
Browse files Browse the repository at this point in the history
* add profile option for frontend profiling to image script

* Update image_classification.py

* Update image_classification.py
  • Loading branch information
szha authored and crazy-cat committed Oct 26, 2017
1 parent d76d050 commit ec740ea
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion example/gluon/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
parser.add_argument('--kvstore', type=str, default='device',
help='kvstore to use for trainer/module.')
parser.add_argument('--log-interval', type=int, default=50, help='Number of batches to wait before logging.')
parser.add_argument('--profile', action='store_true',
help='Option to turn on memory profiling for front-end, '\
'and prints out the memory usage by python function at the end.')
opt = parser.parse_args()

logging.info(opt)
Expand Down Expand Up @@ -166,7 +169,7 @@ def train(epochs, ctx):

net.save_params('image-classifier-%s-%d.params'%(opt.model, epochs))

if __name__ == '__main__':
def main():
if opt.mode == 'symbolic':
data = mx.sym.var('data')
out = net(data)
Expand All @@ -186,3 +189,16 @@ def train(epochs, ctx):
if opt.mode == 'hybrid':
net.hybridize()
train(opt.epochs, context)

if __name__ == '__main__':
if opt.profile:
import hotshot, hotshot.stats
prof = hotshot.Profile('image-classifier-%s-%s.prof'%(opt.model, opt.mode))
prof.runcall(main)
prof.close()
stats = hotshot.stats.load('image-classifier-%s-%s.prof'%(opt.model, opt.mode))
stats.strip_dirs()
stats.sort_stats('cumtime', 'calls')
stats.print_stats()
else:
main()

0 comments on commit ec740ea

Please sign in to comment.