### Install FaceRecognition.NET on Linux (Ubuntu/Debian) Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Installs necessary libraries for FaceRecognition.NET on Ubuntu/Debian-based Linux distributions. ```bash sudo apt-get install libx11-6 libopenblas-dev libgdiplus ``` -------------------------------- ### Run Example with Batch Size Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/FindFacesInBatches/README.md Example command to run the FindFacesInBatches program with a batch size of 32. The output shows the number of faces found per frame and their pixel locations. ```powershell $ pwsh Run.ps1 32 I found 0 face(s) in frame #0. I found 0 face(s) in frame #1. I found 0 face(s) in frame #2. I found 0 face(s) in frame #3. I found 0 face(s) in frame #4. I found 0 face(s) in frame #5. I found 0 face(s) in frame #6. ... ... ... I found 3 face(s) in frame #250. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 - A face is located at pixel location Top: 92, Left: 156, Bottom: 171, Right: 235 I found 3 face(s) in frame #251. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 - A face is located at pixel location Top: 92, Left: 164, Bottom: 171, Right: 243 I found 3 face(s) in frame #252. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 92, Left: 156, Bottom: 171, Right: 235 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 I found 3 face(s) in frame #253. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 92, Left: 156, Bottom: 171, Right: 235 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 I found 3 face(s) in frame #254. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 92, Left: 156, Bottom: 171, Right: 235 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 I found 3 face(s) in frame #255. - A face is located at pixel location Top: 50, Left: 312, Bottom: 145, Right: 407 - A face is located at pixel location Top: 92, Left: 164, Bottom: 171, Right: 243 - A face is located at pixel location Top: 100, Left: 380, Bottom: 179, Right: 459 ``` -------------------------------- ### Run Face Recognition Encoding Example Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/Encoding/README.md Command to run the encoding example, specifying the model and image paths. This will output bounding box coordinates and the face encoding as binary data. ```bash $ dotnet run -c Release -- --model models --image obama-240p.jpg l: 190, t: 32, r: 252, b: 94 -0.0858781188726425, 0.108835116028786, 0.0365724340081215, -0.0589281246066093, 0.0132484100759029, -0.00542659685015678, -0.065446712076664, -0.110336743295193, 0.19452229142189, -0.0979864299297333, 0.2352324873209, 0.0787549242377281, -0.213130414485931, -0.163164556026459, 0.0599864907562733, 0.114194087684155, -0.174584299325943, -0.0919561088085175, -0.0930094122886658, -0.117708653211594, 0.0325165763497353, -0.00997351761907339, 0.106906838715076, 0.0505531094968319, -0.144327610731125, -0.340307205915451, -0.0607180781662464, -0.188485234975815, -0.010340285487473, -0.108085952699184, -0.0919387713074684, 0.00310934125445783, -0.180108249187469, -0.124415650963783, 0.0167518854141235, -0.0189712662249804, 0.0118233505636454, -0.00810264237225056, 0.211996838450432, 0.026537474244833, -0.130677983164787, 0.0932836830615997, 0.0186070054769516, 0.207101136445999, 0.277875900268555, 0.0787801891565323, -0.00383740104734898, -0.0775237083435059, 0.126798510551453, -0.228157266974449, 0.0655233263969421, 0.155302807688713, 0.0920143350958824, 0.0186425745487213, 0.0837418735027313, -0.191329553723335, -0.00609584245830774, 0.0760508179664612, -0.14967368543148, 0.030364228412509, 0.0180820152163506, -0.0949648693203926, -0.0386509634554386, 0.0592935085296631, 0.182954981923103, 0.107051037251949, -0.113879278302193, -0.0532004535198212, 0.131714105606079, -0.0395184531807899, 0.015960929915309, 0.0232246778905392, -0.193916633725166, -0.200455144047737, -0.232742950320244, 0.0793688371777534, 0.374781519174576, 0.173277884721756, -0.211374044418335, -9.25520434975624E-05, -0.21218629181385, 0.0490190535783768, 0.0651776567101479, 0.015591973438859, -0.0640056058764458, -0.136019349098206, -0.0460829176008701, 0.0354794897139072, 0.0894847884774208, 0.0356751903891563, -0.0501493290066719, 0.225857928395271, -0.0144199710339308, 0.0671800822019577, 0.0112739009782672, 0.0495598912239075, -0.14527502655983, -0.0147501565515995, -0.158632963895798, -0.0530679523944855, 0.0203705467283726, -0.030452735722065, 0.0460555553436279, 0.145609840750694, -0.250953495502472, 0.0573373362421989, 0.00578311737626791, -0.0420315787196159, 0.0314476825296879, 0.0746812149882317, -0.0375748537480831, -0.0473008044064045, 0.0588102079927921, -0.238515302538872, 0.237175717949867, 0.259294271469116, 0.0266373176127672, 0.170270383358002, 0.0662055835127831, 0.0214092433452606, -0.000137977302074432, -0.0245289821177721, -0.163018763065338, -0.0655205324292183, 0.0550495907664299, 0.0647143721580505, 0.0707048177719116, 0.00707003846764565 ``` -------------------------------- ### Install FaceRecognition.NET on Linux (RHEL/Fedora/CentOS) Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Installs necessary development packages for FaceRecognition.NET on RHEL-based Linux distributions. ```bash sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm sudo yum install libX11-devel openblas-devel libgdiplus ``` -------------------------------- ### Install libgdiplus on macOS Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Installs the libgdiplus library on macOS using Homebrew. ```bash brew install mono-libgdiplus ``` -------------------------------- ### Training Progress Output Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTraining/README.md Example output showing the training progress, including epoch number, learning rate, average loss, and accuracy metrics for both training and testing datasets. ```text Dataset: Epoch: 3000 Learning Rate: 0.0005 Min Learning Rate: 5E-09 Min Batch Size: 512 Validation Interval: 30 Use Mean: False Output: \result Start load train images Use Cache \train_cache.dat Load train images: 29568 Start load test images Use Cache \test_cache.dat Load test images: 3286 step#: 0 learning rate: 0.0005 average loss: 0 steps without apparent progress: 0 Epoch: 0, learning Rate: 0.0005, average loss: 4.11948018428823 Epoch: 1, learning Rate: 0.0005, average loss: 3.1305690457948 Epoch: 2, learning Rate: 0.0005, average loss: 2.69736696763001 Epoch: 3, learning Rate: 0.0005, average loss: 2.45950934526035 Epoch: 4, learning Rate: 0.0005, average loss: 2.30691530587521 Epoch: 5, learning Rate: 0.0005, average loss: 2.19935585556312 Epoch: 6, learning Rate: 0.0005, average loss: 2.11859311641417 Epoch: 7, learning Rate: 0.0005, average loss: 2.0555247708289 Epoch: 8, learning Rate: 0.0005, average loss: 2.00418632351514 Epoch: 9, learning Rate: 0.0005, average loss: 1.96132853099646 Epoch: 10, learning Rate: 0.0005, average loss: 1.92488743458344 Epoch: 11, learning Rate: 0.0005, average loss: 1.89341635029666 Epoch: 12, learning Rate: 0.0005, average loss: 1.86622101266595 Epoch: 13, learning Rate: 0.0005, average loss: 1.84257901432909 Epoch: 14, learning Rate: 0.0005, average loss: 1.82172028172718 Epoch: 15, learning Rate: 0.0005, average loss: 1.80331000603231 Epoch: 16, learning Rate: 0.0005, average loss: 1.78676114864211 Epoch: 384, learning Rate: 5E-09, average loss: 1.39896950052756 Saved state to Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512 Epoch: 385, learning Rate: 5E-09, average loss: 1.39896063521396 Epoch: 386, learning Rate: 5E-10, average loss: 1.39897608550845 Saved state to Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_ done training training num_right: 14257 training num_wrong: 15311 training accuracy: 0.482176677489177 testing num_right: 1703 testing num_wrong: 1583 testing accuracy: 0.518259281801582 00:00:27 ─────────────────────────────────────────────────────────────────── 100.00% Step 4000 of 4000 00:00:00 ─────────────────────────────────────────────────────────────────── training num_right: 4000 training num_wrong: 0 training accuracy: 1.0000 100.00% Step 1000 of 1000 00:00:00 ─────────────────────────────────────────────────────────────────── testing num_right: 1000 testing num_wrong: 0 testing accuracy: 1.0000 train accuracy: 1.0000, test accuracy: 1.0000 ``` -------------------------------- ### Start Training Process Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTrainingV2/README.md Initiates the training process for the face emotion estimation model. This includes loading images, setting training parameters like epochs and learning rate, and saving results. ```log cd 2022-02-06 17:27:34.0383 [INFO ] Dataset: 2022-02-06 17:27:34.2450 [INFO ] Epoch: 3000 2022-02-06 17:27:34.2450 [INFO ] Learning Rate: 0.001 2022-02-06 17:27:34.2450 [INFO ] Min Learning Rate: 5E-09 2022-02-06 17:27:34.2450 [INFO ] Min Batch Size: 192 2022-02-06 17:27:34.2450 [INFO ] Validation Interval: 1 2022-02-06 17:27:34.2450 [INFO ] Use Mean: False 2022-02-06 17:27:34.2450 [INFO ] Output: \result 2022-02-06 17:27:34.2527 [INFO ] 2022-02-06 17:27:34.2527 [INFO ] Start load train images 2022-02-06 17:32:22.9455 [INFO ] Dataset: 2022-02-06 17:32:23.1567 [INFO ] Epoch: 3000 2022-02-06 17:32:23.1581 [INFO ] Learning Rate: 0.001 2022-02-06 17:32:23.1581 [INFO ] Min Learning Rate: 5E-09 2022-02-06 17:32:23.1581 [INFO ] Min Batch Size: 192 2022-02-06 17:32:23.1581 [INFO ] Validation Interval: 1 2022-02-06 17:32:23.1581 [INFO ] Use Mean: False 2022-02-06 17:32:23.1581 [INFO ] Output: \result 2022-02-06 17:32:23.1581 [INFO ] 2022-02-06 17:32:23.1581 [INFO ] Start load train images 2022-02-06 17:32:49.4177 [INFO ] Load train images: 29568 2022-02-06 17:32:49.4177 [INFO ] Start load test images 2022-02-06 17:32:52.1883 [INFO ] Load test images: 3286 2022-02-06 17:32:52.1883 [INFO ] 2022-02-06 17:37:33.2620 [INFO ] Epoch: 0, learning Rate: 0.001, average loss: 1.83685714839136 2022-02-06 17:38:13.9779 [INFO ] training num_right: 8214 2022-02-06 17:38:13.9779 [INFO ] training num_wrong: 21354 ... 2022-02-06 23:22:20.0030 [INFO ] Epoch: 55, train accuracy: 0.996617965367965, test accuracy: 0.674071819841753 2022-02-06 23:22:30.4702 [INFO ] Best Accuracy Model file is saved for train [0.996617965367965] 2022-02-06 23:27:11.5971 [INFO ] Epoch: 56, learning Rate: 0.0001, average loss: 0.0236947398526919 2022-02-06 23:27:52.3024 [INFO ] training num_right: 29460 2022-02-06 23:27:52.3024 [INFO ] training num_wrong: 108 2022-02-06 23:27:52.3024 [INFO ] training accuracy: 0.996347402597403 2022-02-06 23:27:56.4852 [INFO ] testing num_right: 2231 2022-02-06 23:27:56.4852 [INFO ] testing num_wrong: 1055 2022-02-06 23:27:56.4852 [INFO ] testing accuracy: 0.678940961655508 2022-02-06 23:28:25.0470 [INFO ] Output: \result 2022-02-06 23:28:25.0945 [INFO ] ``` -------------------------------- ### Run Face Detection Application Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/FaceDetection/README.md Command to execute the built face detection application, specifying the directory containing images. Includes example image paths and bounding box coordinates. ```bash $ dotnet run -c Release -- "-d=." .\512px-President_Barack_Obama.jpg,79,314,203,189 .\Lenna.png,228,377,377,228 ``` -------------------------------- ### Load Image File Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Loads an image file into an Image object for processing. This example assumes the image file contains a single human face, but the library can handle images with multiple faces. ```csharp using (Image imageA = FaceRecognition.LoadImageFile(imagePathA)) using (Image imageB = FaceRecognition.LoadImageFile(imagePathB)) ``` -------------------------------- ### Build the Project Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTrainingV2/README.md Build the project in Release configuration using the dotnet CLI. Ensure native DLLs are copied to the output directory. ```bash dotnet build -c Release ``` -------------------------------- ### Build and Run Face Recognition Sample Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/RgbBgr/README.md Commands to build and run the sample application that demonstrates RGB vs. BGR image colorspace differences in face recognition. This includes adding the FaceRecognitionDotNet package and executing the build and run commands. ```bash $ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj $ dotnet add package FaceRecognitionDotNet $ dotnet build -c Release ``` ```bash $ dotnet run -c Release FaceLocations (Hog) File [LTRB]: 218, 219, 373, 374 RGB [LTRB]: 218, 219, 373, 374 BGR [LTRB]: 218, 219, 373, 374 FaceEncodings by File Location (Hog) vs RGB [Distance]: 0 vs BGR [Distance]: 0.202584867566029 FaceEncodings by RGB Location (Hog) vs File [Distance]: 0 vs BGR [Distance]: 0.202584867566029 FaceEncodings by BGR Location (Hog) vs File [Distance]: 0.202584867566029 vs RGB [Distance]: 0.202584867566029 FaceLocations (Cnn) File [LTRB]: 198, 215, 340, 356 RGB [LTRB]: 198, 215, 340, 356 BGR [LTRB]: 212, 229, 354, 371 FaceEncodings by File Location (Cnn) vs RGB [Distance]: 0 vs BGR [Distance]: 0.182024898919954 FaceEncodings by RGB Location (Cnn) vs File [Distance]: 0 vs BGR [Distance]: 0.182024898919954 FaceEncodings by BGR Location (Cnn) vs File [Distance]: 0.182024898919954 vs RGB [Distance]: 0.182024898919954 ``` -------------------------------- ### Build the Project Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/CustomClassificationDemo/README.md Builds the custom classification demo project in Release configuration. ```bash $ dotnet build -c Release ``` -------------------------------- ### Run OpenCVSharp Sample Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/OpenCVSharpSample/README.md Command to run the compiled Release build of the OpenCVSharp sample, specifying the directory containing model files. ```bash $ dotnet run -c Release -- "-m=models" Distance: 0.350636343769049 for obama-240p.jpg Distance: 0.361864784857372 for obama-480p.jpg Distance: 0.37696759951267 for obama-720p.jpg Distance: 0.373414821495045 for obama-1080p.jpg ``` -------------------------------- ### Run Demo with Trained Model Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/HelenTraining/README.md Runs a demo using the trained model file, an input image, and the directory containing model files. ```bash $ dotnet run -c Release -- demo -m "helen\helen-dataset.dat" -i "Steve_Jobs_Headshot_2010-CROP2.jpg" -d "models" ``` -------------------------------- ### Run Head Pose Estimation Demo Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/HeadPoseEstimationDemo/README.md Executes the Head Pose Estimation Demo in Release configuration. Ensure you are in the correct directory. ```bash $ dotnet run -c Release ``` -------------------------------- ### Create Dataset Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTrainingV2/README.md Generate train and test image list files from the 300W-LP dataset using the provided PowerShell script. The trainingRatio parameter controls the split between training and testing data. ```powershell pwsh tools\GenerateTrainTestList.ps1 -rootDirectory \ -trainingRatio 0.9 ``` -------------------------------- ### Create Dataset for Age Training Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/AgeTraining/README.md PowerShell command to create a dataset from the Adience directory, splitting images into training and testing sets. ```powershell pwsh tools\CreateDataset.ps1 -InputDirectory Adience -TrainRate 8 -OutputDirectory AdienceDataset -Max 0 ``` -------------------------------- ### Run Benchmark with Models Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/Benchmark/README.md Command to execute the benchmark application, specifying the directory containing model files. This will output performance timings for various tasks at different resolutions. ```bash $ dotnet run -c Release -- "-m=models" ``` -------------------------------- ### Build FaceRecognitionDotNet Project Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/Encoding/README.md Commands to remove project references, add the FaceRecognitionDotNet NuGet package, and build the project in Release configuration. ```bash $ dotnet remove reference ../../src/FaceRecognitionDotNet/DlibDotNet.csproj $ dotnet remove reference ../../src/FaceRecognitionDotNet/FaceRecognitionDotNet.csproj $ dotnet add package FaceRecognitionDotNet $ dotnet build -c Release ``` -------------------------------- ### Train the Emotion Model Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTraining/README.md Initiate the emotion model training process using the .NET CLI. This command requires the dataset directory, epoch count, learning rates, batch size, validation interval, and output directory. ```bash cd dotnet run -c Release -- train --dataset \ --epoch 3000 \ --lr 0.0005 \ --min-lr 0.000000005 \ --min-batchsize 512 \ --validation-interval 30 \ --output \result ``` -------------------------------- ### Visualize Training Log Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/GenderTraining/README.md Generate a graph from the training log file to visualize the training process. This is useful for analyzing model performance over epochs. ```bash python tools\visualize-log.py utkface-gender-network_600_0.001_1E-05_400.log ``` -------------------------------- ### Preprocess Age Training Dataset Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/AgeTraining/README.md Command to preprocess the created dataset by detecting faces, cropping face areas, and saving the cleaned data. ```bash cd dotnet run -c Release -- preprocess --dataset=AdienceDataset --output=AdienceDataset_preprocessed ``` -------------------------------- ### Generate XML File for Training Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/HelenTraining/README.md Generates an XML file from model files, which is used for training. Specify the directory containing model files and the desired padding. ```bash $ dotnet run -c Release -- generate -m "models" -p 50 ``` -------------------------------- ### Visualize Training Log Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/AgeTraining/README.md Use the provided Python script to visualize the training log generated during the age model training process. This helps in analyzing the model's performance over epochs. ```python python tools\visualize-log.py adience-age-network_600_0.001_1E-05_384_False.log ``` -------------------------------- ### Configure Header File Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/AgeClassification/CMakeLists.txt Configures a header file from a template, replacing placeholders. ```cmake configure_file( ${PROJECT_SOURCE_DIR}/dlib/config.h.in ${PROJECT_SOURCE_DIR}/dlib/config.h @ONLY) ``` -------------------------------- ### Create Dataset for Gender Training Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/GenderTraining/README.md Use this PowerShell script to create a dataset for training and testing gender classification models. It splits images based on the TrainRate and specifies the output directory and maximum number of images. ```powershell pwsh tools\CreateDataset.ps1 -InputDirectory UTKFace -TrainRate 8 -OutputDirectory UTKFaceDataset -Max 0 ``` -------------------------------- ### Add FaceRecognitionDotNet Package Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/FaceEncodingPerformance/README.md Removes the local project reference and adds the FaceRecognitionDotNet NuGet package. Builds the project in Release configuration. ```bash $ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj $ dotnet add package FaceRecognitionDotNet $ dotnet build -c Release ``` -------------------------------- ### Create Dataset from 300W-LP Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/HeadPoseTraining/README.md Use the CreateDataset.ps1 PowerShell script to generate training and testing datasets from the 300W-LP dataset. The TrainRate parameter controls the split ratio. ```powershell pwsh tools\CreateDataset.ps1 -InputDirectory <300W-LP-Dataset_dir> ^ -TrainRate 8 ^ -OutputDirectory <300W-LP-YourDataset_dir> ^ -Max 0 ``` -------------------------------- ### Add FaceRecognitionDotNet Package Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/examples/CustomClassificationDemo/README.md Removes the local project reference and adds the FaceRecognitionDotNet NuGet package to the project. ```bash $ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj $ dotnet add package FaceRecognitionDotNet ``` -------------------------------- ### Initialize FaceRecognition with Model Directory Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Initializes the FaceRecognition instance by specifying the directory containing model files. It's recommended to set the internal encoding to 'shift_jis' to handle non-alphanumeric characters in paths. ```csharp FaceRecognition.InternalEncoding = System.Text.Encoding.GetEncoding("shift_jis"); string directory = "C:\\models" using (FaceRecognition fr = FaceRecognition.Create(directory)) ``` -------------------------------- ### Helen Face Landmark Detection Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Sets up a custom face landmark detector using the Helen dataset model. The 'helen-dataset.dat' file must be present in the 'models' directory. ```cs using (var detector = new HelenFaceLandmarkDetector(Path.Combine("models", "helen-dataset.dat"))) { fr.CustomFaceLandmarkDetector= detector; var locations = fr.FaceLocations(image); var landmarks = fr.FaceLandmark(image, locations , PredictorModel.Custom); } ``` -------------------------------- ### Include Directories and Link Libraries Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/AgeClassification/CMakeLists.txt Includes specified directories and links the dlib::dlib library to the project. ```cmake include_directories(${INCLUDE_DIR}) target_link_libraries(${PROJ_NAME} dlib::dlib ) ``` -------------------------------- ### Run Gender Training Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/GenderTraining/README.md Execute the gender training command with specified dataset, batch size, epochs, and validation interval. This command initiates the training process and outputs training progress and accuracy metrics. ```bash cd dotnet run -c Release -- train -d=UTKFaceDataset -b=400 -e=600 -v=20 ``` ```text Epoch: 600 Learning Rate: 0.001 Min Learning Rate: 1E-05 Min Batch Size: 400 Validation Interval: 20 Start load train images Load train images: 18966 Start load test images Load test images: 4738 step#: 0 learning rate: 0.001 average loss: 0 steps without apparent progress: 0 Epoch: 0, learning Rate: 0.001, average loss: 0.674069870253767 Epoch: 1, learning Rate: 0.001, average loss: 0.61758733607198 step#: 118 learning rate: 0.001 average loss: 0.59829 steps without apparent progress: 0 Epoch: 2, learning Rate: 0.001, average loss: 0.497301147655114 Epoch: 3, learning Rate: 0.001, average loss: 0.477524129911404 Epoch: 4, learning Rate: 0.001, average loss: 0.463913708851862 step#: 242 learning rate: 0.001 average loss: 0.463372 steps without apparent progress: 43 Epoch: 5, learning Rate: 0.001, average loss: 0.41626401307513 Epoch: 6, learning Rate: 0.001, average loss: 0.406071298713716 step#: 366 learning rate: 0.001 average loss: 0.400616 steps without apparent progress: 7 Epoch: 7, learning Rate: 0.001, average loss: 0.377037954321967 Epoch: 8, learning Rate: 0.001, average loss: 0.369290893870278 Epoch: 9, learning Rate: 0.001, average loss: 0.361628701590169 step#: 487 learning rate: 0.001 average loss: 0.361323 steps without apparent progress: 16 Epoch: 10, learning Rate: 0.001, average loss: 0.336463510539802 Saved state to utkface-gender-network_600_0.001_1E-05_400 Epoch: 11, learning Rate: 0.001, average loss: 0.332591397454274 step#: 606 learning rate: 0.001 average loss: 0.329499 steps without apparent progress: 43 Epoch: 12, learning Rate: 0.001, average loss: 0.309775507864488 Epoch: 13, learning Rate: 0.001, average loss: 0.306856178331174 Epoch: 14, learning Rate: 0.001, average loss: 0.302869322321159 step#: 726 learning rate: 0.001 average loss: 0.301861 steps without apparent progress: 28 Epoch: 15, learning Rate: 0.001, average loss: 0.29106002112316 Epoch: 16, learning Rate: 0.001, average loss: 0.285738143057821 step#: 850 learning rate: 0.001 average loss: 0.283248 steps without apparent progress: 72 Epoch: 17, learning Rate: 0.001, average loss: 0.271353094977893 Epoch: 18, learning Rate: 0.001, average loss: 0.270071162790127 Epoch: 19, learning Rate: 0.001, average loss: 0.265453205132239 step#: 974 learning rate: 0.001 average loss: 0.26501 steps without apparent progress: 43 Epoch: 20, learning Rate: 0.001, average loss: 0.253938037542761 Epoch: 20, train accuracy: 0.884266582305178, test accuracy: 0.878429717180245 ... ... Epoch: 590, learning Rate: 1E-05, average loss: 0.00314736557554334 step#: 28368 learning rate: 1e-05 average loss: 0.00314737 steps without apparent progress: 1422 Epoch: 591, Learning Rate: 1E-05, average loss: 0.00301913976009434 Saved state to utkface-gender-network_600_0.001_1E-05_400_ Epoch: 592, Learning Rate: 1E-05, average loss: 0.00311165843646179 step#: 28486 learning rate: 1e-05 average loss: 0.0030405 steps without apparent progress: 1543 Epoch: 593, Learning Rate: 1E-05, average loss: 0.00355719667702782 Epoch: 594, Learning Rate: 1E-05, average loss: 0.00323933126534789 step#: 28606 learning rate: 1e-05 average loss: 0.00313994 steps without apparent progress: 1664 Epoch: 595, Learning Rate: 1E-05, average loss: 0.00382428842364837 Epoch: 596, Learning Rate: 1E-05, average loss: 0.00292338314099893 Epoch: 597, Learning Rate: 1E-05, average loss: 0.00300246790072112 step#: 28727 learning rate: 1e-05 average loss: 0.00304047 steps without apparent progress: 1785 Epoch: 598, Learning Rate: 1E-05, average loss: 0.00299024601756618 Epoch: 599, Learning Rate: 1E-05, average loss: 0.00284008706881824 Saved state to utkface-gender-network_600_0.001_1E-05_400 done training training num_right: 18928 training num_wrong: 38 training accuracy: 0.997996414636718 testing num_right: 4309 testing num_wrong: 429 testing accuracy: 0.909455466441537 ``` -------------------------------- ### Train Head Pose Model Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/HeadPoseTraining/README.md Initiates the training process for a head pose model. Specify the dataset directory, training parameters like gamma and tolerance, and an output directory for results. The process involves loading and caching training and testing images for roll, pitch, and yaw, followed by training and validation steps. ```cmd cd dotnet run -c Release -- train --dataset <300W-LP-YourDataset_dir> ^ --gamma 0.1 ^ --tolerance 0.001 ^ --range 10 ^ --output <300W-LP-YourDataset_dir>\result Dataset: <300W-LP-YourDataset_dir> Tolerance: 0.001 Gamma: 0.1 Range: 10 Pose: All Output: <300W-LP-YourDataset_dir>\result Start load train images Use Cache <300W-LP-YourDataset_dir>\train\cache_Roll.dat Load train images: 4000 Start load test images Use Cache <300W-LP-YourDataset_dir>\test\cache_Roll.dat Load test images: 1000 Training 100.00% Step 4000 of 4000 00:06:55 ─────────────────────────────────────────────────────────────────── Validation for Training data 100.00% Step 4000 of 4000 00:00:01 ─────────────────────────────────────────────────────────────────── training num_right: 4000 training num_wrong: 0 training accuracy: 1.0000 Validation for Test data 100.00% Step 1000 of 1000 00:00:00 ─────────────────────────────────────────────────────────────────── testing num_right: 872 testing num_wrong: 128 testing accuracy: 0.8720 train accuracy: 1.0000, test accuracy: 0.8720 Start load train images Use Cache <300W-LP-YourDataset_dir>\train\cache_Pitch.dat Load train images: 4000 Start load test images Use Cache <300W-LP-YourDataset_dir>\test\cache_Pitch.dat Load test images: 1000 Training 100.00% Step 4000 of 4000 00:00:16 ─────────────────────────────────────────────────────────────────── 100.00% Step 4000 of 4000 00:00:00 ─────────────────────────────────────────────────────────────────── training num_right: 3949 training num_wrong: 51 training accuracy: 0.9873 100.00% Step 1000 of 1000 00:00:00 ─────────────────────────────────────────────────────────────────── testing num_right: 969 testing num_wrong: 31 testing accuracy: 0.9690 train accuracy: 0.9873, test accuracy: 0.9690 Start load train images Use Cache <300W-LP-YourDataset_dir>\train\cache_Yaw.dat Load train images: 4000 Start load test images Use Cache <300W-LP-YourDataset_dir>\test\cache_Yaw.dat Load test images: 1000 100.00% Step 4000 of 4000 00:00:27 ─────────────────────────────────────────────────────────────────── 100.00% Step 4000 of 4000 00:00:00 ─────────────────────────────────────────────────────────────────── training num_right: 4000 training num_wrong: 0 training accuracy: 1.0000 100.00% Step 1000 of 1000 00:00:00 ─────────────────────────────────────────────────────────────────── testing num_right: 1000 testing num_wrong: 0 testing accuracy: 1.0000 train accuracy: 1.0000, test accuracy: 1.0000 ``` -------------------------------- ### Enable NEON Support Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/AgeClassification/CMakeLists.txt Configures C++ compiler flags for NEON support on ARM64 architecture. ```cmake if (${ENABLE_NEON}) # ARM64 ignore mfpu option # https://developer.arm.com/docs/dui0774/i/compiler-command-line-options/-mfpu #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mfpu=neon -fprofile-use -D ENABLE_NEON") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fprofile-use -D ENABLE_NEON") endif() ``` -------------------------------- ### Configure and Build with CUDA Support Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/GenderClassification/CMakeLists.txt Handles build configuration when CUDA is enabled. It disables static linking for CUDA runtime and appends the CUDA include path based on the operating system. ```cmake if (${DLIB_USE_CUDA}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version-cuda.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version-cuda.rc @ONLY) # disable cuda static link set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) # include CUDA Runtime Library if (MSVC OR MSYS OR MINGW) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") elseif(APPLE) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") elseif(UNIX AND NOT APPLE) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") else() message(FATAL_ERROR "Failed to link CUDA Runtime Library") endif() add_library(${PROJ_NAME} SHARED ${HEADERS} ${SOURCES} ${DLIBDOTNET_SHARED_HEADER1} ${DLIBDOTNET_SHARED_HEADER2} ${CMAKE_CURRENT_BINARY_DIR}/version-cuda.rc) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS") add_library(${PROJ_NAME} ${HEADERS} ${SOURCES} ${DLIBDOTNET_SHARED_HEADER1} ${DLIBDOTNET_SHARED_HEADER2} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) else() add_library(${PROJ_NAME} SHARED ${HEADERS} ${SOURCES} ${DLIBDOTNET_SHARED_HEADER1} ${DLIBDOTNET_SHARED_HEADER2} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() endif() ``` -------------------------------- ### Train Helen Dataset Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/HelenTraining/README.md Trains the model using the generated XML file and specifies the number of threads to use. ```bash $ dotnet run -c Release -- train -x "helen\helen-dataset.xml" -t 8 ``` -------------------------------- ### Set Include Directory Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/AgeClassification/CMakeLists.txt Sets the include directory for the project. ```cmake set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../DlibDotNet/src") ``` -------------------------------- ### Initialize FaceRecognition with Model Binary Data Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/wiki/Quickstart Initializes the FaceRecognition instance by providing model binary data directly. This method is useful when model files are embedded as resources. ```csharp var modelParameter = new ModelParameter { PosePredictor68FaceLandmarksModel = File.ReadAllBytes("shape_predictor_68_face_landmarks.dat"), PosePredictor5FaceLandmarksModel = File.ReadAllBytes("shape_predictor_5_face_landmarks.dat"), FaceRecognitionModel = File.ReadAllBytes("dlib_face_recognition_resnet_model_v1.dat"), CnnFaceDetectorModel = File.ReadAllBytes("mmod_human_face_detector.dat") } using (FaceRecognition fr = FaceRecognition.Create(modelParameter )) ``` -------------------------------- ### CPack Configuration Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/AgeClassification/CMakeLists.txt Sets project name and version for CPack, the CMake packaging utility. ```cmake set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) ``` -------------------------------- ### Configure CUDA Build Settings Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/EmotionClassification/CMakeLists.txt Sets up build configurations when DLIB_USE_CUDA is enabled. It disables static linking of the CUDA runtime and appends the CUDA include directory. ```cmake if (${DLIB_USE_CUDA}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version-cuda.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version-cuda.rc @ONLY) set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) if (MSVC OR MSYS OR MINGW) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") elseif(APPLE) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") elseif(UNIX AND NOT APPLE) list(APPEND INCLUDE_DIR "$ENV{CUDA_PATH}/include") else() message(FATAL_ERROR "Failed to link CUDA Runtime Library") endif() ``` -------------------------------- ### Enable ARM NEON Optimization Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/src/GenderClassification/CMakeLists.txt Applies optimization flags for ARM64 architecture when NEON is enabled. It sets optimization level to O3 and enables profile-guided optimization. ```cmake if (${ENABLE_NEON}) # ARM64 ignore mfpu option # https://developer.arm.com/docs/dui0774/i/compiler-command-line-options/-mfpu set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fprofile-use -D ENABLE_NEON") endif() ``` -------------------------------- ### Run Emotion Recognition Model Test Source: https://github.com/takuya-takeuchi/facerecognitiondotnet/blob/master/tools/EmotionTrainingV2/README.md Execute the test command for emotion recognition models. Ensure the 'Models' directory is prepared and specify the dataset and model paths. This command initiates the testing process and outputs detailed logs. ```cmd cd dotnet run -c Debug -- test --dataset ^ --model "Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_5E-05_5E-09_512.dat" ```