@@ -0,0 +1,2887 @@
+%22%22%22 Benchmark script for performance on Raspberry Pi. For example, run the file with:%0A%60python rasp_imagenet_bench.py --model='modbilenet' --host='rasp0' --port=9090%60. For%0Amore details about how to set up the inference environment on Raspberry Pi, Please%0Arefer to NNVM Tutorial: Deploy the Pretrained Model on Raspberry Pi %22%22%22%0Aimport time%0Aimport argparse%0Aimport numpy as np%0Aimport tvm%0Aimport nnvm.compiler%0Aimport nnvm.testing%0Afrom tvm.contrib import util, rpc%0Afrom tvm.contrib import graph_runtime as runtime%0A%0A%0Adef main():%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('--model', type=str, required=True, choices=%5B'resnet', 'mobilenet'%5D,%0A        help=%22The model type.%22)%0A    parser.add_argument('--host', type=str, required=True, help=%22The host address of your Raspberry Pi.%22)%0A    parser.add_argument('--port', type=int, required=True, help=%22The port number of your Raspberry Pi.%22)%0A    parser.add_argument('--opt-level', type=int, default=1, help=%22Level of optimization.%22)%0A    parser.add_argument('--num-iter', type=int, default=50, help=%22Number of iteration during benchmark.%22)%0A    args = parser.parse_args()%0A%0A    opt_level = args.opt_level%0A    target = %22llvm -target=armv7l-none-linux-anueabihf -mcpu=cortex-a53 -mattr=+neon%22%0A%0A    num_iter = args.num_iter%0A    batch_size = 1%0A    num_classes = 1000%0A    image_shape = (3, 224, 224)%0A%0A    data_shape = (batch_size,) + image_shape%0A    out_shape = (batch_size, num_classes)%0A    if args.model == 'resnet':%0A        net, params = nnvm.testing.resnet.get_workload(%0A            batch_size=1, image_shape=image_shape)%0A    elif args.model == 'mobilenet':%0A        net, params = nnvm.testing.mobilenet.get_workload(%0A            batch_size=1, image_shape=image_shape)%0A    else:%0A        raise ValueError('no benchmark prepared for %7B%7D.'.format(args.model))%0A%0A%0A    with nnvm.compiler.build_config(opt_level=opt_level):%0A        with tvm.target.rasp():%0A            graph, lib, params = nnvm.compiler.build(%0A                net, target, shape=%7B%22data%22: data_shape%7D, params=params)%0A%0A    tmp = util.tempdir()%0A    lib_fname = tmp.relpath('net.o')%0A    lib.save(lib_fname)%0A%0A    remote = rpc.connect(args.host, args.port)%0A    remote.upload(lib_fname)%0A%0A    ctx = remote.cpu(0)%0A    rlib = remote.load_module('net.o')%0A    rparams = %7Bk: tvm.nd.array(v, ctx) for k, v in params.items()%7D%0A%0A    module = runtime.create(graph, rlib, ctx)%0A    module.set_input('data', tvm.nd.array(np.random.uniform(size=(data_shape)).astype(%22float32%22)))%0A    module.set_input(**rparams)%0A    module.run()%0A    out = module.get_output(0, tvm.nd.empty(out_shape, ctx=ctx))%0A    out.asnumpy()%0A%0A    print('benchmark args: %7B%7D'.format(args))%0A    ftimer = module.module.time_evaluator(%22run%22, ctx, num_iter)%0A    for i in range(3):%0A        prof_res = ftimer()%0A        print(prof_res)%0A        # sleep for avoiding cpu overheat%0A        time.sleep(45)%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add Benchmark for Rasp (#68)