Commit graph

326 commits

Author SHA1 Message Date
iperov
6f86c68e65 add AMP model 2021-05-29 18:57:35 +04:00
iperov
fdb143ff47 added AMD/Intel cards support via DirectX12 ( DirectML backend ) 2021-04-22 18:19:15 +04:00
iperov
93fe480eca revert 2021-04-19 13:35:14 +04:00
iperov
af0b3904fc XSeg trainer: additional dssim loss. 2021-04-15 21:43:47 +04:00
iperov
8d46cd94fd upd pretrain option help 2021-03-23 16:07:50 +04:00
iperov
e47b602ec8 SAEHD: random flip replaced with random SRC flip(default False) and random DST flip(default True) 2021-03-23 15:13:10 +04:00
iperov
b333fcea4b dump_ckpt 2021-03-23 15:00:24 +04:00
iperov
11add4cd4f update GAN model 2021-01-03 19:25:39 +04:00
iperov
54fc3162ed new gan 2021-01-03 01:08:20 +04:00
iperov
ad5733c5bb upd PatchDiscriminator 2020-12-31 17:38:41 +04:00
iperov
ae9e16b4a5 SAEHD: new GAN 2020-12-30 14:33:14 +04:00
iperov
db83a21244 Eyes priority is replaced with Eyes and mouth priority,
Helps to fix eye problems during training like "alien eyes" and wrong eyes direction.
Also makes the detail of the teeth higher.

New default values with new model:
Archi : ‘liae-ud’
AdaBelief : enabled
2020-12-20 09:45:22 +04:00
iperov
dd037d2dea SAEHD: lr_dropout now can be used with AdaBelief 2020-12-18 12:42:10 +04:00
iperov
40d18896b7 SAEHD: change help 2020-12-16 18:25:25 +04:00
iperov
da058cf17f remove lrcos from adabelief 2020-12-11 20:34:14 +04:00
iperov
26ed582aff fix xseg 2020-12-11 20:25:30 +04:00
iperov
1ee7798fb9 . 2020-12-11 17:56:39 +04:00
iperov
704b5dc072 SAEHD: added new option Use AdaBelief optimizer?
Experimental AdaBelief optimizer. It requires more VRAM, but the accuracy of the model is higher, and lr_dropout is not needed.
2020-12-11 15:48:27 +04:00
iperov
254a7cf5cf fix xseg training 2020-12-11 15:47:11 +04:00
iperov
35945b257c fix dimensions error 2020-12-11 14:34:37 +04:00
iperov
b9c9e7cffd fix depth_to_space for tf2.4.0. Removing compute_output_shape in leras, because it uses CPU device, which does not support all ops. 2020-12-11 11:28:33 +04:00
Colombo
6134e57762 options_show_override{} for model summary in pretrain mode 2020-07-27 16:37:13 +04:00
Colombo
1435dd3dd1 SAEHD: now random_warp is disabled for pretraining mode by default 2020-07-26 16:11:08 +04:00
Colombo
ce95af9068 SAEHD: write_preview_history now works faster
The frequency at which the preview is saved now depends on the resolution.
For example 64x64 – every 10 iters. 448x448 – every 70 iters.
2020-07-18 11:03:13 +04:00
Colombo
58670722dc fix 2020-07-17 17:40:32 +04:00
Colombo
b9b97861e1 fix mask for style losses 2020-07-17 17:34:07 +04:00
Colombo
e8b04053e4 SAEHD:
Changed help for “Learning rate dropout” option:

When the face is trained enough, you can enable this option to get extra sharpness and reduce subpixel shake for less amount of iterations.

Enabled it before “disable random warp” and before GAN. n disabled. y enabled

cpu enabled on CPU. This allows not to use extra VRAM, sacrificing 20% time of iteration.

 Changed help for GAN option:

Train the network in Generative Adversarial manner.

Forces the neural network to learn small details of the face.

Enable it only when the face is trained enough and don't disable.

Typical value is 0.1

improved GAN. Now it produces better skin detail, less patterned aggressive artifacts, works faster.
https://i.imgur.com/Nbh3mw1.png
2020-07-16 22:19:17 +04:00
Colombo
44e6970dc5 changed help for gan_power 2020-06-30 12:37:12 +04:00
Colombo
4e998aff93 . 2020-06-24 10:06:31 +04:00
Colombo
f90723c9f9 SAEHD: ‘uniform_yaw’ now always enabled in pretrain mode. 2020-06-21 00:57:48 +04:00
Colombo
53222839c6 SAEHD: for -d archis resolution should be divided by 32 2020-06-19 14:21:41 +04:00
Colombo
0c2e1c3944 SAEHD:
Maximum resolution is increased to 640.

‘hd’ archi is removed. ‘hd’ was experimental archi created to remove subpixel shake, but ‘lr_dropout’ and ‘disable random warping’ do that better.

‘uhd’ is renamed to ‘-u’
dfuhd and liaeuhd will be automatically renamed to df-u and liae-u in existing models.

Added new experimental archi (key -d) which doubles the resolution using the same computation cost.
It is mean same configs will be x2 faster, or for example you can set 448 resolution and it will train as 224.
Strongly recommended not to train from scratch and use pretrained models.

New archi naming:
'df' keeps more identity-preserved face.
'liae' can fix overly different face shapes.
'-u' increased likeness of the face.
'-d' (experimental) doubling the resolution using the same computation cost
Examples: df, liae, df-d, df-ud, liae-ud, ...

Improved GAN training (GAN_power option).  It was used for dst model, but actually we don’t need it for dst.
Instead, a second src GAN model with x2 smaller patch size was added, so the overall quality for hi-res models should be higher.

Added option ‘Uniform yaw distribution of samples (y/n)’:
	Helps to fix blurry side faces due to small amount of them in the faceset.

Quick96:
	Now based on df-ud archi and 20% faster.

XSeg trainer:
	Improved sample generator.
Now it randomly adds the background from other samples.
Result is reduced chance of random mask noise on the area outside the face.
Now you can specify ‘batch_size’ in range 2-16.

Reduced size of samples with applied XSeg mask. Thus size of packed samples with applied xseg mask is also reduced.
2020-06-19 09:45:55 +04:00
Colombo
7f11713730 fix 2020-06-11 21:29:39 +04:00
Colombo
82f405ed49 Trainer: fixed "Choose image for the preview history". Now you can switch between subpreviews using 'space' key.
Fixed "Write preview history". Now it writes all subpreviews in separated folders
https://i.imgur.com/IszifCJ.jpg
also the last preview saved as _last.jpg before the first file
https://i.imgur.com/Ls1AOK4.jpg
thus you can easily check the changes with the first file in photo viewer
2020-06-10 10:20:13 +04:00
Colombo
af98407f06 SAEHD: lr_dropout now can be ‘n’, ‘y’, ‘cpu’. ‘n’ and ’y’ are the same as before.
‘cpu’ mean enabled on CPU. This allows not to use extra VRAM, sacrificing 20% time of iteration.

SAEHD: resolution >= 256 now has second dssim loss function
2020-06-08 14:18:33 +04:00
Colombo
2b7364005d Added new face type : head
Now you can replace the head.
Example: https://www.youtube.com/watch?v=xr5FHd0AdlQ
Requirements:
	Post processing skill in Adobe After Effects or Davinci Resolve.
Usage:
1)	Find suitable dst footage with the monotonous background behind head
2)	Use “extract head” script
3)	Gather rich src headset from only one scene (same color and haircut)
4)	Mask whole head for src and dst using XSeg editor
5)	Train XSeg
6)	Apply trained XSeg mask for src and dst headsets
7)	Train SAEHD using ‘head’ face_type as regular deepfake model with DF archi. You can use pretrained model for head. Minimum recommended resolution for head is 224.
8)	Extract multiple tracks, using Merger:
a.	Raw-rgb
b.	XSeg-prd mask
c.	XSeg-dst mask
9)	Using AAE or DavinciResolve, do:
a.	Hide source head using XSeg-prd mask: content-aware-fill, clone-stamp, background retraction, or other technique
b.	Overlay new head using XSeg-dst mask

Warning: Head faceset can be used for whole_face or less types of training only with XSeg masking.

XSegEditor: added button ‘view trained XSeg mask’, so you can see which frames should be masked to improve mask quality.
2020-04-04 09:28:06 +04:00
Colombo
0fb912e91f Trainer: added --silent-start cmd option 2020-04-02 13:05:04 +04:00
Colombo
3702531898 SAEHD: ‘Face style power’ and ‘Background style power’ are now available for whole_face
New help messages for these options:

Face style power
Learn the color of the predicted face to be the same as dst inside mask.
If you want to use this option with 'whole_face' you have to use XSeg trained mask.
Warning: Enable it only after 10k iters, when predicted face is clear enough to start learn style.
Start from 0.001 value and check history changes.
Enabling this option increases the chance of model collapse

Background style power
      Learn the area outside mask of the predicted face to be the same as dst.
If you want to use this option with 'whole_face' you have to use XSeg trained mask.
This can make face more like dst.
Enabling this option increases the chance of model collapse. Typical value is 2.0
2020-03-30 19:46:17 +04:00
Colombo
6d3607a13d New script:
5.XSeg) data_dst/src mask for XSeg trainer - fetch.bat
Copies faces containing XSeg polygons to aligned_xseg\ dir.
Useful only if you want to collect labeled faces and reuse them in other fakes.

Now you can use trained XSeg mask in the SAEHD training process.
It’s mean default ‘full_face’ mask obtained from landmarks will be replaced with the mask obtained from the trained XSeg model.
use
5.XSeg.optional) trained mask for data_dst/data_src - apply.bat
5.XSeg.optional) trained mask for data_dst/data_src - remove.bat

Normally you don’t need it. You can use it, if you want to use ‘face_style’ and ‘bg_style’ with obstructions.

XSeg trainer : now you can choose type of face
XSeg trainer : now you can restart training in “override settings”
Merger: XSeg-* modes now can be used with all types of faces.

Therefore old MaskEditor, FANSEG models, and FAN-x modes have been removed,
because the new XSeg solution is better, simpler and more convenient, which costs only 1 hour of manual masking for regular deepfake.
2020-03-30 14:00:40 +04:00
Colombo
497a7eec94 fix preview_history 2020-03-29 14:50:02 +04:00
Colombo
4e744cf184 Colab: change save preview iters to every 100 2020-03-28 13:58:41 +04:00
Colombo
6687213fa5 SAEHD: fixed the use of pretrained liae model, now it produces less face morphing 2020-03-27 00:15:18 +04:00
Colombo
eddebedcf6 SAEHD: added 'dfuhd' and 'liaeuhd' archi 2020-03-23 22:01:44 +04:00
Colombo
45582d129d added XSeg model.
with XSeg model you can train your own mask segmentator of dst(and src) faces
that will be used in merger for whole_face.

Instead of using a pretrained model (which does not exist),
you control which part of faces should be masked.

Workflow is not easy, but at the moment it is the best solution
for obtaining the best quality of whole_face's deepfakes using minimum effort
without rotoscoping in AfterEffects.

new scripts:
	XSeg) data_dst edit.bat
	XSeg) data_dst merge.bat
	XSeg) data_dst split.bat
	XSeg) data_src edit.bat
	XSeg) data_src merge.bat
	XSeg) data_src split.bat
	XSeg) train.bat

Usage:
	unpack dst faceset if packed

	run XSeg) data_dst split.bat
		this scripts extracts (previously saved) .json data from jpg faces to use in label tool.

	run XSeg) data_dst edit.bat
		new tool 'labelme' is used

		use polygon (CTRL-N) to mask the face
			name polygon "1" (one symbol) as include polygon
			name polygon "0" (one symbol) as exclude polygon

			'exclude polygons' will be applied after all 'include polygons'

		Hot keys:
		ctrl-N			create polygon
		ctrl-J			edit polygon
		A/D 			navigate between frames
		ctrl + mousewheel 	image zoom
		mousewheel		vertical scroll
		alt+mousewheel		horizontal scroll

		repeat for 10/50/100 faces,
			you don't need to mask every frame of dst,
			only frames where the face is different significantly,
			for example:
				closed eyes
				changed head direction
				changed light
			the more various faces you mask, the more quality you will get

			Start masking from the upper left area and follow the clockwise direction.
			Keep the same logic of masking for all frames, for example:
				the same approximated jaw line of the side faces, where the jaw is not visible
				the same hair line
			Mask the obstructions using polygon with name "0".

	run XSeg) data_dst merge.bat
		this script merges .json data of polygons into jpg faces,
		therefore faceset can be sorted or packed as usual.

	run XSeg) train.bat
		train the model

		Check the faces of 'XSeg dst faces' preview.

		if some faces have wrong or glitchy mask, then repeat steps:
			split
			run edit
			find these glitchy faces and mask them
			merge
			train further or restart training from scratch

Restart training of XSeg model is only possible by deleting all 'model\XSeg_*' files.

If you want to get the mask of the predicted face in merger,
you should repeat the same steps for src faceset.

New mask modes available in merger for whole_face:

XSeg-prd	  - XSeg mask of predicted face	 -> faces from src faceset should be labeled
XSeg-dst	  - XSeg mask of dst face        -> faces from dst faceset should be labeled
XSeg-prd*XSeg-dst - the smallest area of both

if workspace\model folder contains trained XSeg model, then merger will use it,
otherwise you will get transparent mask by using XSeg-* modes.

Some screenshots:
label tool: https://i.imgur.com/aY6QGw1.jpg
trainer   : https://i.imgur.com/NM1Kn3s.jpg
merger    : https://i.imgur.com/glUzFQ8.jpg

example of the fake using 13 segmented dst faces
          : https://i.imgur.com/wmvyizU.gifv
2020-03-15 15:12:44 +04:00
Colombo
dde856499d saehd: removed liaech 2020-03-13 13:04:26 +04:00
Colombo
61472cdaf7 global refactoring and fixes,
removed support of extracted(aligned) PNG faces. Use old builds to convert from PNG to JPG.

fanseg model file in facelib/ is renamed
2020-03-13 08:09:00 +04:00
Colombo
ba58621361 SAEHD: removed option learn_mask, it is now enabled by default 2020-03-10 10:36:08 +04:00
Colombo
b0b9072981 added XSeg model 2020-03-09 13:09:46 +04:00
Colombo
9eb15065f9 _ 2020-03-09 10:15:29 +04:00
Colombo
d731930537 fixes 2020-03-09 00:18:01 +04:00