Skip to content

How to use batch inference? #6245

@zengjie617789

Description

@zengjie617789

I want to test the images with batch inference.
I construct the data which shape is (target_size, target_size, batch_size, 3), and the key code is like below:

for (int i = 0; i < batch_size; ++i) {
            dfd_ex.input(0, in_batch);
            ncnn::Mat out;
            dfd_ex.extract(499, out);
            float pred = out.row(0)[0];
            pred = (1.f / (1.f + exp(-pred)));
            preds.push_back(pred);
        }

I found the pred results is not correct and alway got the same outputs;
Futhermore, I found the official doc like this:

int max_batch_size = vkdev->info.compute_queue_count();

ncnn::Mat inputs[1000];
ncnn::Mat outputs[1000];

#pragma omp parallel for num_threads(max_batch_size)
for (int i=0; i<1000; i++)
{
    ncnn::Extractor ex = net1.create_extractor();
    ex.input("data", inputs[i]);
    ex.extract("prob", outputs[i]);
}

I canot do this like because I create a data which make batch_size as the depth dims.
Anyone who can help me will be appreciated !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions