ncnn编译及打印每一层的时间

最新从 https://github.com/Tencent/ncnn下载下来的安装包。
protobuf 版本最好为3.6.1,用系统默认的2.6.1编译报错。

编译过之后,让我们来跑一下benchmark打印每一层的时间.
先看代码:
Net::forward_layer

#if NCNN_BENCHMARK
            double start = get_current_time();
            int ret = layer->forward_inplace(bottom_top_blob, opt);
            double end = get_current_time();
            benchmark(layer, bottom_top_blob, bottom_top_blob, start, end);
#else
            int ret = layer->forward_inplace(bottom_top_blob, opt);
#endif // NCNN_BENCHMARK

已经定义好了,每一层的时间,并且已经在benchmark中进行输出,那我们来看一下benchmark.

void benchmark(const Layer* layer, double start, double end)
{
    fprintf(stderr, "%-24s %-24s %8.2lfms", layer->type.c_str(), layer->name.c_str(), end - start);
    fprintf(stderr, "    |");
    fprintf(stderr, "\n");
}

void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double start, double end)
{
    fprintf(stderr, "%-24s %-24s %8.2lfms", layer->type.c_str(), layer->name.c_str(), end - start);
    fprintf(stderr, "    |    feature_map: %4d x %-4d    inch: %4d    outch: %4d", bottom_blob.w, bottom_blob.h, bottom_blob.c, top_blob.c);
    if (layer->type == "Convolution")
    {
        fprintf(stderr, "     kernel: %1d x %1d     stride: %1d x %1d",
                ((Convolution*)layer)->kernel_w,
                ((Convolution*)layer)->kernel_h,
                ((Convolution*)layer)->stride_w,
                ((Convolution*)layer)->stride_h
        );
    }
    fprintf(stderr, "\n");
}

重载了两个函数,一个只有时间,另一个带有bottom_blob与top_blob层.也就是说,只要把编译的benchmark打开,就能打印的.

2.修改编译选项

option(NCNN_BENCHMARK "print benchmark information for every layer" ON) #将OFF改为ON
...
add_subdirectory(benchmark) #放开

在ncnn/build目录下,cmake … && make -j4就能看到benchncnn了,然后./benchncnn 运行就好,若是提示加载失败,那就把param文件拷贝到同目录中.
结果如下:
在这里插入图片描述有详细的,各层的时间已经当前层的情况...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值