Skip to content

Instantly share code, notes, and snippets.

@berak
Created December 27, 2019 13:09
Show Gist options
  • Save berak/b41e9c7b60911213b020b3b388430044 to your computer and use it in GitHub Desktop.
Save berak/b41e9c7b60911213b020b3b388430044 to your computer and use it in GitHub Desktop.
dnn multiple images
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
string folder = "c:/data/dnn/tcnn/";
// small 5 pt facial keypoint model from gil levy
dnn::Net net = dnn::readNet(folder + "vanilla_deplay.prototxt", folder + "vanillaCNN.caffemodel");
string imp = "C:\\data\\faces\\lfw40_crop\\Abdullah_Gul_0002.jpg";
Mat img = imread(imp);
cout << img.size() << endl;
auto run = [&](const Mat &blob) {
net.setInput(blob);
Mat out = net.forward();
cout << out.size << endl;
cout << out << endl;
};
run(dnn::blobFromImage(img,1,Size(40,40)));
vector<Mat> vec(10,img);
run(dnn::blobFromImages(vec,1,Size(40,40)));
return 0;
}
/*
[96 x 96]
1 x 10
[-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415]
10 x 10
[-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415;
-0.18263823, -0.2103174, 0.12870482, -0.15074131, -0.055463284, 0.042840961, -0.13968539, 0.22529338, 0.11189944, 0.26449415]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment