takuya-takeuchi / FaceRecognitionDotNet

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

How to convert encoding data to double array #106

Closed arnab77in closed 4 years ago

arnab77in commented 4 years ago

I want to save encoding data to database. How to convert encoding data to double array do that I can save it

takuya-takeuchi commented 4 years ago

@arnab77in FaceEncoding has Serializable attribute and you can serialize.

arnab77in commented 4 years ago

@takuya-takeuchi Thanks it is working. I have another issue. Is there any way I can put some indexing while comparing a face with list of faces so that it can return the index of the image it matched. that way I can find out which image it matched. otherwise I can to match every single face one by one.

Can you also tell me what should be the idle performance(time taken) to match an image with 100K images.

takuya-takeuchi commented 4 years ago

I have another issue. Is there any way I can put some indexing while comparing a face with list of faces so that it can return the index of the image it matched. that way I can find out which image it matched. otherwise I can to match every single face one by one.

Does it mean is there cache architecture, right? Answer is no. This task is not FRDN. FRDN is thin wrapper of face_recognition.

Can you also tell me what should be the idle performance(time taken) to match an image with 100K images.

I have no data about face compare performance. But there is other performance data. https://github.com/takuya-takeuchi/FaceRecognitionDotNet/issues/4

timiil commented 4 years ago

please consider the line below inside https://github.com/takuya-takeuchi/FaceRecognitionDotNet/blob/master/src/FaceRecognitionDotNet/FaceEncoding.cs

internal Matrix<double> Encoding => this._Encoding;

change to ===>

public Matrix<double> Encoding => this._Encoding;

that can make us easy persit the landmark data into any storage or any kind db we want.

arnab77in commented 4 years ago

I have done it as per @takuya-takeuchi advice SerializationInfo sz = new SerializationInfo(strdata.GetType(), format);

        encoding.GetObjectData(sz, scon);

        var dbl = (double[])sz.GetValue("_Encoding", typeof(double[]));

Thanks

takuya-takeuchi commented 4 years ago

@timiil What's the arnab77in's aproach wrong? API should be simple and not expose what we need not to use. FaceEncoding already supports serialize.

that can make us easy persit the landmark data

What does it mean? FaceEncoding does not contain landmark data. It contains face feature data (yes, this metaphor is not correct but not bad).

timiil commented 4 years ago

my spell mistake, i means sometimes we need to persit the 'feature data' (128 * 64bit double)' into any kind of persitance backend.

may be we can expose like :

public ReadOnlyCollection<double> RawEncoding => ...

i think this aproach is simpler than SerializationInfo :)

takuya-takeuchi commented 4 years ago

@timiil What purpose do you use double[] data? You have to create FaceEncoding object even though deserialize from storage. But FaceEncoding has not public constructors. How do you use it on FaceRecognitionDotNet?

I will NOT expose public constructors.

Is there some useful idea for using raw encoding except for serialize?

timiil commented 4 years ago

one example: we need to get a known people's face features (128 * double) use FRDN on a x64 web server and its db. therefore we need to transform the data to a remote device over network,the device may running python | golang | something just use dlib internally.

that should be one reason we need the feature data quickly persist and transport.

takuya-takeuchi commented 4 years ago

@timiil OK. I understand.

I will provide GetRawEncoding method. But I will not expose public constructors. Because

takuya-takeuchi commented 4 years ago

Done. 419383d2ed3082a4d37cd983915684b0b1b3d79e

timiil commented 4 years ago

Thanks you and agree with you that do not expose the constructor of FaceEncoding.

here is another consideration please, the FaceEncoding class do not have properties to record: 'the image where its from', 'the rectangle where its from', 'the Entity where its related in real world' . so when we done a 1:n or m:n FacesCompare,it is really hard to related back the picture, the rectangle(we may draw a box on that face), the Entity(we should display the name or other info below face box) with the FaceEncoding. if we can have these properties inside the FaceEncoding class. the above tasks should be very easy. and I think these properties just free for get set,convient to use, do not slow down the Ecluid Distance computation.