Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.12k stars 4.14k forks source link

Why is my 1D convolution not working? #5571

Open poltomo opened 2 months ago

poltomo commented 2 months ago

Why is my 1D convolution implementation not working?

The output shape comes out to 0x0x0.

Also where is the C API documenation?

More info: I am linking against the arm64-v8a version for an android device with a qualcomm soc.

Secondary question

How do I get max performance for a 1d convolution. Where's the implementation for that max performance conv?

#include <iostream>
#include "ncnn/cpu.h"
#include "ncnn/net.h"
#include "ncnn/layer.h"

int main() {
    int input_length = 1 << 16;
    int kernel_length = 4;

    ncnn::Mat input(input_length);
    ncnn::Mat kernel(kernel_length);
    std::cout << input.h << ' ' << input.w << ' ' << input.c << std::endl;
    std::cout << kernel.h << ' ' << kernel.w << ' ' << kernel.c << std::endl;
    ncnn::Mat output;

    ncnn::Option opt;
    opt.num_threads = 1;

    ncnn::Layer* conv1d = ncnn::create_layer(81);

    ncnn::ParamDict pd;
    pd.set(0, 1);
    pd.set(1, 1);
    pd.set(2, 1);
    pd.set(3, 0);
    pd.set(4, (float)(kernel.w));

    conv1d->load_param(pd);
    conv1d->load_model(ncnn::ModelBinFromMatArray(&kernel));

    conv1d->create_pipeline(opt);

    conv1d->forward(input, output, opt);

    conv1d->destroy_pipeline(opt);

    delete conv1d;

    std::cout << "Output shape: " << output.w << " x " << output.h << " x " << output.c << std::endl;
}
nihui commented 3 weeks ago

see https://github.com/Tencent/ncnn/issues/2568

use high level api