Search code examples
c++opencvcomputer-visionartificial-intelligenceopenvino

Dynamic batch is not supported on Intel NCS2 vpu


I'm trying to run FP16 person-detection-retail-0013 and person-reidentification-retail-0079 on Intel Neural Compute Stick hardware, but once I run the application to load the nets on the device I get this exception:

[INFERENCE ENGINE EXCEPTION] Dynamic batch is not supported

I've load the net with setting of the max batch size to 1 and I've started my project from the pedestrian tracker demo into the OpenVINO toolkit:

main.cpp --> CreatePedestrianTracker

    CnnConfig reid_config(reid_model, reid_weights);
    reid_config.max_batch_size = 16;

    try {
        if (ie.GetConfig(deviceName, CONFIG_KEY(DYN_BATCH_ENABLED)).as<std::string>() != 
            PluginConfigParams::YES) {
            reid_config.max_batch_size = 1;
            std::cerr << "[DEBUG] Dynamic batch is not supported for " << deviceName << ". Fall back 
            to batch 1." << std::endl;
        }
    }
    catch (const InferenceEngine::details::InferenceEngineException& e) {
        reid_config.max_batch_size = 1;
        std::cerr << e.what() << " for " << deviceName << ". Fall back to batch 1." << std::endl;
    }

Cnn.cpp --> void CnnBase::InferBatch

void CnnBase::InferBatch(
const std::vector<cv::Mat>& frames,
std::function<void(const InferenceEngine::BlobMap&, size_t)> fetch_results) const {
const size_t batch_size = input_blob_->getTensorDesc().getDims()[0];

size_t num_imgs = frames.size();
for (size_t batch_i = 0; batch_i < num_imgs; batch_i += batch_size) {

    const size_t current_batch_size = std::min(batch_size, num_imgs - batch_i);

    for (size_t b = 0; b < current_batch_size; b++) {
        matU8ToBlob<uint8_t>(frames[batch_i + b], input_blob_, b); 
    }

    if ((deviceName_.find("MYRIAD") == std::string::npos) && (deviceName_.find("HDDL") == 
        std::string::npos)) {
        infer_request_.SetBatch(current_batch_size); 
    }

    infer_request_.Infer();

    fetch_results(outputs_, current_batch_size);
 }
}

I suppose that the problem could be the topology of the detection net, but I ask if anyone has had the same problem and solved the issue.
Thank's.


Solution

  • I am afraid, myriad plugin does not support dynamic batch. Please try an updated version of the demo. You can find it, for example, here: https://github.com/opencv/open_model_zoo/tree/master/demos/pedestrian_tracker_demo The demo is updated not to use dynamic batch at all.