Giter VIP home page Giter VIP logo

Comments (4)

takuya-takeuchi avatar takuya-takeuchi commented on May 23, 2024

@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.

from facerecognitiondotnet.

maoshanli avatar maoshanli commented on May 23, 2024

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.

from facerecognitiondotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 23, 2024

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.

from facerecognitiondotnet.

maoshanli avatar maoshanli commented on May 23, 2024

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

from facerecognitiondotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.