GAN128 gets worse and develops moiré patter
When training with GAN128 after a certain number of epochs (about 15hours of training on modern GPU)
- result becomes worse: faces more disfigured than at the first stages of training (both discriminator and generator).
- as GAN very quickly learns to swap eyes and mouth extremely accurately it gradually losses the ability as more epochs pass instead of improving further.
- develops horrible moire pattern at both mask and the output (even raw) non existent at the data-sets (in fact data starts to look 64x64 printed at 128x128 tiles)
That happens irrespective of training patterns which are taken from various source for both dataA and dataB. I tried tv recoding, movie flics, 3d cartoons, my own footage of me and friends. The behaviors is always the same.
Mask moire pattern

Disfigured with moire. Despite A and B are super similar, that's why I choose those to test if GAN128 works.

I get the same behavior. The results are much cleaner if I drop the mask:
new_image = numpy.copy( image[:,:,:3] )
masked_fake_output = rgb
masked_fake_output = rgb
fake = fake_rgb
Sorry for the poor quality diff, the formatting gets bad if I paste it with the +/-.
Missed a spot in my ugly hacking. Need to also delete this line to drop the mask during conversion:
new_face = mask * new_face + (1 - mask) * normalized_face
Thanks a lot a I shall report with my findings
When the size of the kernel and stride don't play well with each other it can lead to checkerboard-like convolution artifacts in the resulting image. This article can give some insight into why this happens.
I am thinking that perhaps the line of code below is why we are seeing the moire patterns.
x = SeparableConv2D(f, kernel_size=3, strides=2, kernel_initializer=conv_init, use_bias=False, padding="same")(x)
Line 66 of plugins/Model_GAN128/Model.py
Thanks everyone for you feedback.
I realized while I was "tweaking" the Original model that GAN encoder doesn't have enough memory/neurons to hold the data (encoded_dim). GAN is also one Conv2d layer big to be trainable. My experiments shown that these kind of architecture can converge relatively well with 5 Conv2D layers which is 1 more than Original and one less than GAN. Also my unproven speculation that initial Conv2D layers should have a bigger windows which should span horizontal (something like (5,6) they are inverted). I haven't tested this yet, but I can see results are too generalized on horizontal features, but that yet to be proven.
PS: My current Original model tweak is times faster than GAN and gives a better result. It converges even with different versions of face such as 3D, photos, sketches, and drawings mixed together as target_B. My Original model tweak also plays nice with one-to-many approach. Only problem I found it gives too much preference to colors in favor of the shape (ie it would try to match, say, yellowish targets with photos taken in sunlight). If someone knows how to modify this part that would be very welcome. In general its OK, but the emphasys is a little to big.
PSS: I am aware that isn't a chat. The latest findings also that batch size should not be a power of 2 it has to be even (though not every model requires that neither) and it has to be smaller than number of samples (which can be overcame with a few lines of code). In fact decreasing-train-restoring back batch size can make net trainable again as it re-arranges its clusters positions.
@andenixa Are you planning on doing a pull request of your OriginalHighRes model?
He already has. You can test it by checking out the staging branch https://github.com/deepfakes/faceswap/tree/staging
Going to post a model update in a day or so with an improvement that should alleviate or solve this issue by implementing ICNR initialization of the convolution kernels.
See this paper by the same authors of Pixel Shuffle for an overview https://arxiv.org/ftp/arxiv/papers/1707/1707.02937.pdf
Been playing with your model and works pretty well. I'll test your update as soon as you release it.
On Thu, May 17, 2018, 1:09 AM kvrooman [email protected] wrote:
Going to post a model update in a day or so with an improvement that should alleviate or solve this issue by implementing ICNR initialization of the convolution kernels.
See this paper by the same authors of Pixel Shuffle for an overview https://arxiv.org/ftp/arxiv/papers/1707/1707.02937.pdf
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/deepfakes/faceswap/issues/339#issuecomment-389755581, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGgmTBFadZl08-NiiH1WLJI4o0zwsjks5tzRQKgaJpZM4TOI7X .
@kvrooman any news? I'm burning for a test 'cause GAN works best with 2 of my facesets until moiré kicks in
I noticed lr=1e-04 sometimes contributes to long lasting moire patterns (beats me why) (instead of 5e-05 in faceswap) and since GAN has additional mask layer it reinforces that pattern and sometimes embeds it as a "valid" outcome. I can observe the same pattern with Adam lr=1e-4 at my mask-less Model though it tends to vanish with time.
I tried OriginalHighRes and it takes a lot longer to train, but it's expected.
But it seems to develop a moire pattern too. I'm around 0.03x loss though, so I'll see if it improves when loss goes down.
@Kirin-kun I am going to make it slightly faster. I wouldn't watch for loss as its not really an objective measurement of completion. If you can see the predictor output (the rightmost image in the 1st and second triplet cols) to have eyes with clearly visible pupil (better if you see eyelashes), and facial expression follows the original during convert then the training is finished. As for moire I shall try to get rid of it.
Once I trained a net at 50k epochs I had all blurry silhouette of teeth and eyes with 0.04 loss, at 200k epochs I had crisp eyes and every tooth visible with clear tongue and.. well loss was still 0.04
GAN v2.2 release
2018-06-25 Model update: faceswap-GAN v2.2 has been released. The main improvements of v2.2 model are its capability of generating realistic and consistent eyeballs (results are shown below, or Ctrl+F for eyeballs), as well as its higher quality of video results with face alignment.
@tjess78 in my experience any 128x model is able to generate realistic consistent eyeballs.
To achieve that all that is needed to:
- raise
Dense layerdimensions by about 50% - add additional
Conv2d layerbefore to the last one. - train your Net at
-bs 16or higher for ~120k epochs
This video was made by me using a Non-GAN autoencoder model using the instructions above. The video is SFW.
Prerequisites for data set -B is that it shall:
- consist of crystal crisp frames with no blur or smudges
- should not contain pics with partially obscured faces
- have even lighting conditions, i.e. no blinds shadows overlapping the face
- have approximately same number of frames for every angle with very similar shots removed to expedite the training
Dear @andenixa, your video looks incredible. How did you achieve this nearly seamless face replacement? No matter which model I use, the superimposed mask looks clearly above the background body. Did you use any smoothing algorithm?
@agilebean its regular seamless mode on the left and masked with slight smoothing at the right side. Both modes use histogram matching. I use a slight mask erosion (about 10-15%). That's pretty much everything. I suggest to not use any sharpening parameter to avoid the mask to be visible.
@andenixa thanks a lot - forgive me to ask again, how did you
- enable histogram matching
- mask erosion
- smoothing with the faceswap.py command? I didn't see these options, the closest was perceptual loss...
Those are options during the conversion, not the training. -mh activates histogram matching and with -e you can set the erosion kernel size.
Hello @andenixa and @HelpSeeker,
thanks so much for your tips.
The histogram matching and seamless options made a big difference.
As for mask erosion with the -e option, how do you specify 15%?
-e .15or -e 15 or else?