I try to launch intel inference engine example under OpenCV.
Link to example info: https://software.intel.com/en-us/articles/OpenVINO-IE-Samples#inpage-nav-3
Security Barrier Camera Demo
I use OpenCV 3.4.3 compiled with inference engine.
In particular I have problems with following model /intel_models/vehicle-attributes-recognition-barrier-0039. This pretrained model (.xml + .bin files) runs successfully in intel inference engine demo app. This net has two output softmax layers ("color" and "type", "type" is the final network layer so its result is returned from net.forward())
Piece of code:
try
{
cv::dnn::Net net = cv::dnn::readNet(model, config);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_DEFAULT);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
if (net.empty())
{
std::cerr << "Failed! Net is empty!\n";
return EXIT_FAILURE;
}
else
{
std::cout << "Success!\n";
cv::Mat car = cv::imread(file);
if (car.empty())
{
std::cerr << "Failed to load " << file << '\n';
return EXIT_FAILURE;
}
cv::Mat conv_car;
car.convertTo(conv_car, CV_32FC3);
int w = 72, h = 72;
std::cout
<< "car type: " << car.type() << '\n'
<< "conv car type: " << conv_car.type() << '\n';
while (true)
{
auto input = cv::dnn::blobFromImage(
conv_car,
1.,
cv::Size((int)w, (int)h),
cv::Scalar(0, 0 ,0),
false,
false,
CV_32F
);
net.setInput(input);
cv::Mat output = net.forward();
output = output.reshape(1, 1);
std::cout
<< "output.size(): " << output.size() << '\n'
<< "output.elemSize(): " << output.elemSize() << '\n'
<< "output.data():\n";
for (size_t i = 0; i < output.cols; ++i)
std::cout << output.at<float>(0, i) << ' ';
cv::Point classIdPoint;
double confidence;
minMaxLoc(output, 0, &confidence, 0, &classIdPoint);
int classId = classIdPoint.x;
std::cout << "\nclass id: " << classId << " confidence: " << confidence << '\n';
cv::imshow("img", car);
char k = cv::waitKey(0) % 256;
if (k == 27)
break;
}
}
}
catch (cv::Exception& e)
{
std::cout << "Failed!\n";
std::cout << e.what() << '\n';
}
When I call
net.forward()
or
net.forward("type")
I get a reasonable output which match one of intel native sample
output.size(): [4 x 1]
output.elemSize(): 4
output.data():
0.999998 2.33588e-09 6.7388e-09 2.31872e-06
But when I call
net.forward("color")
I get strange output different every time. Though output size looks correct.
output.size(): [7 x 1]
output.elemSize(): 4
output.data():
2.57396e-12 2.61858e+20 7.58788e+31 1.94295e-19 7.71303e+31 5.08303e+31 1.80373e+28
class id: 4 confidence: 7.71303e+31
I have also failed to correctly use net.forward() overloads for multiple outputs.
The only idea I have is that to get the output of intermediate layer in some specific way.
Link to pretrained network: https://download.01.org/openvinotoolkit/R4/vehicle-attributes-recognition-barrier-0039/FP32/