faceswap icon indicating copy to clipboard operation
faceswap copied to clipboard

Supporting alignment.json

Open Jack29913 opened this issue 8 years ago • 18 comments

Right now convert takes a full frame. First it detects the face then crops it, runs model and finally merges it back. But we've already done half the job during extraction. We detected the face and cropped it to train on it. So it doesn't make sense to do it all over again(especially if we want to use cnn). Also algorithm may miss some faces or output some garbage images that we got rid out before training. With this approach we have absolutely no control what images it uses. We should use the extracted images to process and merge only those. For example 1adrianb's face-detector outputs alignment.json after extraction. With using something like that we would know where the face is on the frame and where to merge it without processing again

Jack29913 avatar Feb 07 '18 12:02 Jack29913

What if you want to convert 20000 frames, but only train on a subset of 8000 of those?

BeatHarness avatar Feb 07 '18 12:02 BeatHarness

So you would prefer converting 12000 frames you didn't train on? I don't understand. If you want to convert a video you should use all the frames. Maybe you are confusing with Data B?

Jack29913 avatar Feb 07 '18 13:02 Jack29913

My feelings where a bit mitigated on alignment.json. With the HOG it was not a big deal because it is fast, but i agree that with MMOD/CNN maybe the game changed.

The most annoying part for me was the fact that with alignments.json we depend on a file that almost no one can edit and it makes the convert rely on something that may be lost / corrupted.

However, we still can add an option to generate the alignments.json, it is just a matter of serializing a data we already have. On the convert side, I don't think it is a big deal either, but for now I want to focus on the GAN, so I let this for now, but if someone wants to take it, I'm fine

Clorr avatar Feb 07 '18 13:02 Clorr

Face detection algorithm sometimes confuse objects with faces. Last time I converted something algorithm also converted the painting on the wall. Right now only way to solve this issue is feeding the algorithm with single filter-face file. But then algorithm fails to detect all the faces because of the angle of something. Isn't this a big issue or am I missing something?

Using the json file is not mandatory but then we should tell the algorithm only to use what's in the dataset. But that means comparing every time it detects a new "face" during convert

Jack29913 avatar Feb 07 '18 13:02 Jack29913

Bah the problem here is more that we have many users and only few coders. My priorities depend on what i want to do which is not fake porn, so I understand your point, but on my side I don't have this problem for now at least...

Clorr avatar Feb 07 '18 13:02 Clorr

Who said anything about fake porn? It's a general issue if you want to convert a scene or algorithm gives you a false-positive output. Of course I'm not saying what you should do or when you should do. I'm just pointing an issue for everyone here.

Jack29913 avatar Feb 07 '18 13:02 Jack29913

This is within my capabilities, and I'm willing to do it.

Might take me a couple of days (need to do some paid work).

Are we particularly attached to json? something more performant would be great, like pickle or shelve (both python stdlib)?

I will serialise it as such:

{
    "filename-aligned-0001.tif": {
        "position": [...],
        "landmarks": [...]
    }
...
}

and then when we retrieve the data, for each image that we have, try and get some data, otherwise skip it.

Does that sound good?

I will make it with multiple serializers for meatbag functionality. so that people can share their aligned datasets without worrying about evaluating someone elses pickle, or edit the files directly.

gdunstone avatar Feb 07 '18 14:02 gdunstone

\ o /

Glad you want to take that part ;-) On the json part I strongly encourage you to stick to what is done already in the official repo, otherwise we will encounter endless issues ;-)

You could do a new format, but then don't use the same name. But I'm less keen on that because we would create yet another format...

Do you know where to find the original format?

Clorr avatar Feb 07 '18 14:02 Clorr

(Also, don't only listen to me ;-) )

Clorr avatar Feb 07 '18 14:02 Clorr

You can check the original code posted on Reddit as starting point (I can provide the scripts if you can't find them). Basically when extracting algorithm outputs a json file containing info about the images. Then we swap the face only within training set. Now we have a folder of converted faces. Then using this file and converted images we do the merges.

Jack29913 avatar Feb 07 '18 14:02 Jack29913

I can do both.

I can structure the json serializer around the one in the fakeapp repo, and the other serializers, Ill just do whatever works.

It most likely already uses a similar structure to what I'm thinking of, maybe with different names.

gdunstone avatar Feb 07 '18 14:02 gdunstone

I know how the process works. My only real gripes are that json isn't exactly an ideal format for this kind of data. It doesn't really matter all that much. I will add options for more serializers.

gdunstone avatar Feb 07 '18 14:02 gdunstone

Json is readable and hence can be edited easily. Last time, I merged additional files into my original json file. This is the only reason json is ideal. But if you can provide same functionality for another format I think it's not an issue

Jack29913 avatar Feb 07 '18 14:02 Jack29913

You'd read the json once at initialisation the processing time for which is dwarfed by even the most trivial image operations you'd do with it's contents.

The ability to immediately slice and dice human-readable text (for manual insertion of new batches or externally augmented training samples) isn't worth the time saved.

dfaker avatar Feb 07 '18 19:02 dfaker

I think yaml might be better due to being able to easily concat files.

On 8 Feb. 2018 6:52 am, "dfaker" [email protected] wrote:

You'd read the json once at initialisation the processing time for which is dwarfed by even the most trivial image operations you'd do with it's contents.

The ability to immediately slice and dice human-readable text (for manual insertion of new batches or externally augmented training samples) isn't worth the time saved.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/deepfakes/faceswap/issues/135#issuecomment-363890006, or mute the thread https://github.com/notifications/unsubscribe-auth/AEDEeNNM9bh45rzhPKhmnnsU3T-dQTPyks5tSf8agaJpZM4R8ptp .

gdunstone avatar Feb 08 '18 09:02 gdunstone

That'd be a nice benefit, some numbers on serialization here: https://gist.github.com/hartleybrody/9164c1b1d28842255e4b#file-serialization-py

dfaker avatar Feb 08 '18 10:02 dfaker

Im surprised at some of those numbers (like bson wtf), I suppose json is almost a straight repr for most common python types.

gdunstone avatar Feb 08 '18 12:02 gdunstone

This has been merged.

gdunstone avatar Feb 12 '18 03:02 gdunstone