DNN forwards only first image
I make input for neural network with cv.dnn.blobFromImages, and then run forward function. Number of input images = 20. But I always get only one output, for first blob. I saw documentation of blobFromImages and forward fucntions but it didn't help. I got the same result on Python and C++
imgs = [cv.imread(e) for e in os.listdir()] #20 images
cv_input = cv.dnn.blobFromImages(imgs, 1, (64,64))
cvNet.setInput(cv_input)
pred = cvNet.forward()
pred # array([[1.]], dtype=float32)
.............
vector<vector<cv::Mat>> pred;
// images = vector of cv::Mat
cv::Mat inp = cv::dnn::blobFromImages(images, 1. / 255, cv::Size(64, 64), cv::Scalar(), true);
cnn_cl.setInput(inp);
cnn_cl.forward(pred);
opencv version ? what kind of network do you load ?
OpenCV 4.1. I use CNN with 64x64x3 on input and sigmoid on output layer. I got it by converting keras→tensorflow→openCV DNN. It works correctly on single image.
how should the output look like ? what is expected ? (is it just a classification network ?)
It is a binary classificator. When I run it on single images i got correct outputs.
Out:
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]
But with running in multiple images I got only one prediction: array([[1.]], dtype=float32)
seems to work as expected with 4.2.0 or master. can you try to update ?
The same result on python with cv__version__ = 4.2.0
Did I correctly understand? You got multiple output after blobFromImages and one forward command?
unfortunately, yes, it works for me
btw,
vector<Mat> pred;
not vector vector (and that works, too ;()try :
I tried. But it doesnt work.
I see that my original keras model uses «channels last» so input array has shape (20, 64, 64, 3) But opencv works with (20, 3, 64, 64). Could this fact be causing the problem? I guess no but ..