takuya-takeuchi / FaceRecognitionDotNet

The world's simplest facial recognition api for .NET on Windows, MacOS and Linux
MIT License
1.26k stars 308 forks source link

Unexpected version found while deserializing dlib::add_skip_layer when load Emotion Estimator Model #231

Open Augmented-Chords opened 1 year ago

Augmented-Chords commented 1 year ago

I downloaded Corrective re-annotation of FER - CK+ - KDEF and ran program FaceRecognitionDotNet/tools /EmotionTraining then I got the following results.

2023-07-03 15:58:55.6154 [INFO ] done training
2023-07-03 15:58:57.4307 [INFO ] training num_right: 13199
2023-07-03 15:58:57.4307 [INFO ] training num_wrong: 16369
2023-07-03 15:58:57.4307 [INFO ] training accuracy:  0.446394751082251
2023-07-03 15:58:57.6349 [INFO ] testing num_right: 1593
2023-07-03 15:58:57.6349 [INFO ] testing num_wrong: 1693
2023-07-03 15:58:57.6349 [INFO ] testing accuracy:  0.484783931832015
2023-07-03 15:58:57.7513 [INFO ] 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512.tmp' was cleaned and 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512.dat' is created.
2023-07-03 15:58:57.7654 [INFO ] 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_test_best_0.48934875228241.tmp' was cleaned and 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_test_best_0.48934875228241.dat' is created.
2023-07-03 15:58:57.7761 [INFO ] 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_train_best_0.449979707792208.tmp' was cleaned and 'F:\fer_ckplus_kdef\result\Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_train_best_0.449979707792208.dat' is created.

Everything looks fine. But I encountered this error

DlibDotNet.SerializationException: 'An error occurred while trying to read the first object from the file dlib-models/Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_test_best_0.48934875228241.dat.
ERROR: Unexpected version found while deserializing dlib::add_skip_layer.

When I ran the following code

            using (var fr = FaceRecognition.Create("dlib-models"))
            using (var image = FaceRecognition.LoadImage(imageFile))
            {
                var box = fr.FaceLocations(image, model: Model.Cnn).FirstOrDefault();
               //↓Unhandled exception occurs on this line
                using (var emotionEstimator = new SimpleEmotionEstimator("dlib-models/Corrective_re-annotation_of_FER_CK+_KDEF-mlp_3000_0.0005_5E-09_512_test_best_0.48934875228241.dat"))
                {
                    fr.CustomEmotionEstimator = emotionEstimator;
                    var emotion = fr.PredictEmotion(image, box);
                }
            }

I trained this model using DlibDotNet (CPU) in 19.21.0.20220724 . I tried to run my program with FaceRecognitionDotNet (CPU) in 1.3.0.7 and 1.3.0.6 on my Windows 11 PC. The same error occurred in both.🥺