Browse Source

Add print statements for 4 dimensions benchmark (#5148)

tags/20240102
Justin Fung GitHub 2 years ago
parent
commit
465debe9bb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions
  1. +3
    -0
      benchmark/benchncnn.cpp
  2. +52
    -0
      src/benchmark.cpp
  3. +1
    -0
      src/net.cpp

+ 3
- 0
benchmark/benchncnn.cpp View File

@@ -232,6 +232,9 @@ static std::vector<ncnn::Mat> parse_shape_list(char* s)
const std::vector<int>& shape = shapes[i];
switch (shape.size())
{
case 4:
mats.push_back(ncnn::Mat(shape[0], shape[1], shape[2], shape[3]));
break;
case 3:
mats.push_back(ncnn::Mat(shape[0], shape[1], shape[2]));
break;


+ 52
- 0
src/benchmark.cpp View File

@@ -34,6 +34,10 @@
#include "layer/convolutiondepthwise.h"
#include "layer/deconvolution.h"
#include "layer/deconvolutiondepthwise.h"
#include "layer/convolution3d.h"
#include "layer/convolutiondepthwise3d.h"
#include "layer/deconvolution3d.h"
#include "layer/deconvolutiondepthwise3d.h"

#include <stdio.h>
#endif // NCNN_BENCHMARK
@@ -111,6 +115,10 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
{
sprintf(in_shape_str, "[%3d, %3d, %3d *%d]", bottom_blob.w, bottom_blob.h, bottom_blob.c, bottom_blob.elempack);
}
if (bottom_blob.dims == 4)
{
sprintf(in_shape_str, "[%3d, %3d, %3d, %3d *%d]", bottom_blob.w, bottom_blob.h, bottom_blob.d, bottom_blob.c, bottom_blob.elempack);
}

if (top_blob.dims == 1)
{
@@ -124,6 +132,10 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
{
sprintf(out_shape_str, "[%3d, %3d, %3d *%d]", top_blob.w, top_blob.h, top_blob.c, top_blob.elempack);
}
if (top_blob.dims == 4)
{
sprintf(out_shape_str, "[%3d, %3d, %3d, %3d *%d]", top_blob.w, top_blob.h, top_blob.d, top_blob.c, top_blob.elempack);
}

fprintf(stderr, " | %22s -> %-22s", in_shape_str, out_shape_str);

@@ -159,6 +171,46 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
((DeconvolutionDepthWise*)layer)->stride_w,
((DeconvolutionDepthWise*)layer)->stride_h);
}
else if (layer->type == "Convolution3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((Convolution3D*)layer)->kernel_w,
((Convolution3D*)layer)->kernel_h,
((Convolution3D*)layer)->kernel_d,
((Convolution3D*)layer)->stride_w,
((Convolution3D*)layer)->stride_h,
((Convolution3D*)layer)->stride_d);
}
else if (layer->type == "ConvolutionDepthWise3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((ConvolutionDepthWise3D*)layer)->kernel_w,
((ConvolutionDepthWise3D*)layer)->kernel_h,
((ConvolutionDepthWise3D*)layer)->kernel_d,
((ConvolutionDepthWise3D*)layer)->stride_w,
((ConvolutionDepthWise3D*)layer)->stride_h,
((ConvolutionDepthWise3D*)layer)->stride_d);
}
else if (layer->type == "Deconvolution3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((Deconvolution3D*)layer)->kernel_w,
((Deconvolution3D*)layer)->kernel_h,
((Deconvolution3D*)layer)->kernel_d,
((Deconvolution3D*)layer)->stride_w,
((Deconvolution3D*)layer)->stride_h,
((Deconvolution3D*)layer)->stride_d);
}
else if (layer->type == "DeconvolutionDepthWise3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((DeconvolutionDepthWise3D*)layer)->kernel_w,
((DeconvolutionDepthWise3D*)layer)->kernel_h,
((DeconvolutionDepthWise3D*)layer)->kernel_d,
((DeconvolutionDepthWise3D*)layer)->stride_w,
((DeconvolutionDepthWise3D*)layer)->stride_h,
((DeconvolutionDepthWise3D*)layer)->stride_d);
}
fprintf(stderr, "\n");
}



+ 1
- 0
src/net.cpp View File

@@ -194,6 +194,7 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& blob_mats, cons
bottom_blob.dims = blob_mats[bottom_blob_index].dims;
bottom_blob.w = blob_mats[bottom_blob_index].w;
bottom_blob.h = blob_mats[bottom_blob_index].h;
bottom_blob.d = blob_mats[bottom_blob_index].d;
bottom_blob.c = blob_mats[bottom_blob_index].c;
bottom_blob.elempack = blob_mats[bottom_blob_index].elempack;
bottom_blob.elemsize = blob_mats[bottom_blob_index].elemsize;


Loading…
Cancel
Save