Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. #225

Closed
maoshanli opened this issue Jan 4, 2023 · 4 comments

Comments

@maoshanli
Copy link

The exception is an accidental exception,but it makes the program crash. The following is the exception:
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at DlibDotNet.NativeMethods.LossMetric_operator_matrixs(Int32 id, IntPtr obj, MatrixElementType element_type, IntPtr[] matrix_array, Int32 matrix_array_len, Int32 templateRows, Int32 templateColumns, UInt32 batch_size, IntPtr& ret)
at DlibDotNet.Dnn.LossMetric.Operator[T](IEnumerable`1 images, UInt64 batchSize)

The initialization of ShapePredictor was written in the initialization of a class by singleton pattern.
I have scanned the related issues like #5,I have checked the model file full path(D:\RoomCX\VideoToPicture) , I also download the .dat files serveral times,the problem still exist.
Please let me know how i can correct this

Thanks

@takuya-takeuchi
Copy link
Owner

@takuya-takeuchi
Could you show me minimal code to reproduce issue?

LossMetric_operator_matrixs is invoked when inference.
Therefore, I guess you try to invoke this methods from multiple thread.
If so, you must create multiple FaceRecognition object per thread.

Thanks.

@maoshanli
Copy link
Author

The code:
public static FaceRecognitionEx Inst
{
get
{
if (m_instance == null)
m_instance = new FaceRecognitionEx();
return m_instance;
}
}
private FaceRecognitionEx()
{
detector = Dlib.GetFrontalFaceDetector();
sp = ShapePredictor.Deserialize("shape_predictor_68_face_landmarks.dat");
net = DlibDotNet.Dnn.LossMetric.Deserialize("dlib_face_recognition_resnet_model_v1.dat");
}
FrontalFaceDetector detector;
ShapePredictor sp;
LossMetric net;
public List<float[]> GetFeature(string imgpath)
{
/*..........
var faces = new List<Matrix>();
try
{
using (var img = Dlib.LoadImageAsMatrix(imgpath))
{
foreach (var face in detector.Operator(img))
{
var shape = sp.Detect(img, face);
var faceChipDetail = Dlib.GetFaceChipDetails(shape, 150, 0.25);
var faceChip = Dlib.ExtractImageChip(img, faceChipDetail);

                        faces.Add(faceChip);
                    }
                    /*.......
            catch
            {
                LogManager.face.Info($"[获取人脸特征失败]");
                features = null;
            }
            foreach (var face in faces)
                face.Dispose();
        } while (false);
        return features;
  }

The function " GetFeature" was invoked by multiple thread.By my understanding,the “shape_predictor_68_face_landmarks.dat” loaded once can improve the performance.I have tried to load the .dat for each image,the cpu can't support.

@takuya-takeuchi
Copy link
Owner

takuya-takeuchi commented Jan 5, 2023

The function " GetFeature" was invoked by multiple thread.

In GetFeature, net.Operator is invoked from multiple thread, doesn't it? If so, this schenario is not be supported.
davisking/dlib#544 (comment)

You have to create FaceRecognitionEx instance for each thread.
Or you can invoke net.Operator on one thread by using lock mechanism.

DlibDotNet.Dnn.LossMetric would not be slow operation different from face detection.

@maoshanli
Copy link
Author

Thank you very much!net.Operator invoked from multiple thread lead to the problem.I have sovled the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants