Beispiel #1
0
        static void getTestBenchamrkRes(CaffeModel model, string iscorrect)
        {
            string        fatherDir  = @"C:\Data\Alignment_TestBenchmark_Equalized\" + iscorrect;
            int           count      = 0;
            DirectoryInfo fatherInfo = new DirectoryInfo(fatherDir);

            DirectoryInfo[] childrenInfos = fatherInfo.GetDirectories();
            foreach (var childrenInfo in childrenInfos)
            {
                FileInfo[] files = childrenInfo.GetFiles("*.jpg", SearchOption.AllDirectories);
                if (files.Length != 2)
                {
                    continue;
                }
                else
                {
                    Bitmap[] bits1      = new[] { new Bitmap(files[0].FullName) };
                    Bitmap[] bits2      = new[] { new Bitmap(files[1].FullName) };
                    float[]  a          = model.ExtractBitmapOutputs(bits1, "ip1", 0);
                    float[]  b          = model.ExtractBitmapOutputs(bits2, "ip1", 0);
                    float    confidency = CaffeModel.CosineDistanceProb(a, b);
                    Write(@"C:\Users\BALTHASAR\Documents\MATLAB\FaceTest\" + iscorrect + ".txt", confidency.ToString());
                }
                count++;
                Console.WriteLine(count);
            }
        }
Beispiel #2
0
        static SortedList <int, float> lfw_fe(string model, string net, string pair, string imgDir)
        {
            SortedList <int, float> results = new SortedList <int, float>();
            var          fe = new CaffeModel(net, model);
            StreamReader sr = new StreamReader(pair, Encoding.Default);
            string       line;
            int          label = 1;

            while ((line = sr.ReadLine()) != null)
            {
                string[] sArray = line.Split('\t');
                if (sArray.Length == 3)
                {
                    DirectoryInfo child      = new DirectoryInfo(imgDir + sArray[0]);
                    FileInfo[]    file       = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[]       a          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[1]) - 1].FullName }, "eltmax_fc5", 0);
                    float[]       b          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[2]) - 1].FullName }, "eltmax_fc5", 0);
                    float         confidency = CaffeModel.CosineDistanceProb(a, b);
                    results.Add(label, confidency);
                }
                if (sArray.Length == 4)
                {
                    DirectoryInfo child = new DirectoryInfo(imgDir + sArray[0]);
                    FileInfo[]    file  = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[]       a     = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[1]) - 1].FullName }, "eltmax_fc5", 0);
                    //
                    child = new DirectoryInfo(imgDir + sArray[2]);
                    file  = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[] b          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[3]) - 1].FullName }, "eltmax_fc5", 0);
                    float   confidency = CaffeModel.CosineDistanceProb(a, b);
                    results.Add(-1 * label, confidency);
                }
                Console.WriteLine(label);
                label++;
            }
            return(results);
        }