from __future__ import absolute_import import argparse from analysis.CaffeA import * from Caffe import caffe_net from analysis.utils import save_csv """ Before you analyse your network, [Netscope](http://ethereon.github.io/netscope/#/editor) is recommended to visiualize your network. Command:`python caffe_analyser.py [-h] prototxt outdir shape` - The prototxt is the path of the prototxt file. - The outdir is path to save the csv file. - The shape is the input shape of the network(split by comma `,`), image shape should be: channel, batch_size, image_height, image_width. For example `python caffe_analyser.py resnet_18_deploy.prototxt analys_result.csv 1,3,224,224` """ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('prototxt', help='path of the prototxt file', type=str) parser.add_argument('outdir', help='path to save the csv file', type=str) parser.add_argument('shape', help='input shape of the network(split by comma `,`), image shape should be: batch,c,h,w', type=str) args = parser.parse_args() shape = [int(i) for i in args.shape.split(',')] net = caffe_net.Prototxt(args.prototxt) blob_dict, layers = profiling(net, Blob(shape)) save_csv(layers, args.outdir)
'--shape', help= 'input shape of the network(split by comma `,`), image shape should be: batch,c,h,w', type=str) parser.add_argument('--out', help='path to save the csv file', default='/tmp/pytorch_analyse.csv', type=str) parser.add_argument('--class_args', help='args to init the class in python file', default='', type=str) args = parser.parse_args() path, filename = os.path.split(args.path) filename = os.path.splitext(filename)[0] sys.path.insert(0, path) exec('from %s import %s as Net' % (filename, args.name)) if isinstance(Net, nn.Module): net = Net elif issubclass(Net, nn.Module): net = Net(*args.class_args.split()) else: assert ( "Error, The Net is not a instance of nn.Module or subclass of nn.Module" ) shape = [int(i) for i in args.shape.split(',')] x = Variable(torch.rand(shape)) blob_dict, layers = analyse(net, x) save_csv(layers, args.out)
import argparse from analysis.CaffeA import * from Caffe import caffe_net from analysis.utils import save_csv if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('prototxt', help='path of the prototxt file', type=str) parser.add_argument('outdir', help='path to save the csv file', type=str) parser.add_argument( 'shape', help= 'input shape of the network(split by comma `,`), image shape should be: batch,h,w,c', type=str) args = parser.parse_args() shape = [int(i) for i in args.shape.split(',')] net = caffe_net.Prototxt(args.prototxt) blob_dict, not_ref = profilling(net, Blob(shape)) save_csv(not_ref, args.outdir)
type=str) parser.add_argument('--func_kwargs', help='kwargs parse to the function, eg. a=1,b=2', default='', type=str) args = parser.parse_args() path, filename = os.path.split(args.path) path = os.path.abspath(path) print(path) filename = os.path.splitext(filename)[0] sys.path.insert(0, path) exec('from %s import %s as sym' % (filename, args.name)) if isinstance(sym, mxnet.sym.Symbol): sym = sym elif hasattr(sym, '__call__'): _kwargs = args.func_kwargs.split(',') kwargs = [] for a in _kwargs: if a == '': continue kwargs.append(a.split('=')) kwargs = dict(kwargs) sym = sym(*args.func_args.split(), **kwargs) else: assert ( "Error, The sym is not a instance of mxnet.sym.Symbol or function") shape = [int(i) for i in args.shape.split(',')] profiling_symbol(sym, shape) save_csv(tracked_layers, '/tmp/a.csv')
help= 'kwargs dict parse to the function, eg. --func_kwargs {a=1,c="OP"}', default='', type=str) args = parser.parse_args() path, filename = os.path.split(args.path) path = os.path.abspath(path) print(path) filename = os.path.splitext(filename)[0] sys.path.insert(0, path) exec('from %s import %s as sym' % (filename, args.name)) if isinstance(sym, mxnet.sym.Symbol): sym = sym elif hasattr(sym, '__call__'): if args.func_kwargs != '': kwargs = eval(args.func_kwargs) else: kwargs = {} if args.func_args != '': func_args = eval(args.func_args) else: func_args = [] sym = sym(*func_args, **kwargs) else: assert ( "Error, The sym is not a instance of mxnet.sym.Symbol or function") shape = [int(i) for i in args.shape.split(',')] profiling_symbol(sym, shape) save_csv(tracked_layers, '/tmp/mxnet_analyse.csv')