- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a batch of Mat stored as vector of 4.
Currently I am using following way to write data to NN input buffer
1. Get pointer to input blob
unsigned char *input_buffer; unsigned char *input_buffer_current_image; for (auto &item : nn_read_data.input_info) { input_name = item.first; auto input_data = item.second; auto input = nn_read_data.infer_request.GetBlob(input_name); input_buffer = input->buffer().as<PrecisionTrait<Precision::U8>::value_type *>(); }
2. Write images
for (int mb=0; mb < batchSize; mb++){ frame = image_batch.at(mb); for (size_t pixelnum = 0; pixelnum < channel_size; ++pixelnum){ for (size_t ch = 0; ch < num_channels; ++ch){ input_buffer[full_image_size*mb + (ch * channel_size) + pixelnum] = frame.at<cv::Vec3b> (pixelnum)[ch]; } }
}
In this way it's taking around 34 ms to write a batch of 4. This is way more compared to OpenCV's
blobFromImages() and net.setInput()
combined.
Is there any faster/efficient way to perform the same?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Shelke, Sagar,
Please look at the hello_autoresize_classification sample. There you'll see
cv::Mat image = cv::imread(input_image_path); Blob::Ptr imgBlob = wrapMat2Blob(image); // just wrap Mat data by Blob::Ptr without allocating of new memory infer_request.SetBlob(input_name, imgBlob); //
Note the wrapMat2Blob call.
Hope it helps,
Thanks,
Shubha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Shubha,
I have a vector of 4 Mats. function "wrapMat2Blob" writes data for a single image Mat.
After looking into hello_shape_infer_ssd example,
I tried using matU8ToBlob but for batch write, it does the same thing as I mentioned in original question.
Blob::Ptr input = infer_request.GetBlob(input_name); for (size_t b = 0; b < batch_size; b++) { matU8ToBlob<uint8_t>(image, input, b); }
Is there any implementation of "wrapMat2Blob" for batch of Mat?
Thanks,
Sagar
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page