Commit Graph

116 Commits

Author SHA1 Message Date
iperov
a1ba64be10 _ 2021-10-18 10:51:25 +04:00
iperov
55b947eab5 XSeg: added pretrain option. 2021-07-30 17:24:21 +04:00
iperov
fdb143ff47 added AMD/Intel cards support via DirectX12 ( DirectML backend ) 2021-04-22 18:19:15 +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
254a7cf5cf fix xseg training 2020-12-11 15:47:11 +04:00
Colombo
b2f9ea8637 fix integer dimensions in model initialization 2020-10-03 22:38:29 +04:00
Colombo
3e7ee22ae3 Merger: fix load time of xseg if it has no model files 2020-07-29 00:41:53 +04:00
Colombo
770da74a9b fix cv2.resize interpolation 2020-07-03 18:40:35 +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
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
c3ce06a588 facetype.mouth 2020-03-28 09:38:09 +04:00
Colombo
9b070e10a6 fixed face jitter 2020-03-18 13:40:06 +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
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
5eaa59cea6 _ 2020-03-09 16:42:05 +04:00
Colombo
a030ff6951 refactoring 2020-03-09 13:08:32 +04:00
Colombo
45abcff3d1 refactoring 2020-03-09 11:05:26 +04:00
Colombo
143792fd31 added fanseg for future WF segmentation model 2020-03-08 00:49:12 +04:00
Colombo
54548afe1a refactoring 2020-03-06 01:21:38 +04:00
Colombo
c1bf3f53ba add comment 2020-02-28 19:31:33 +04:00
Colombo
a6f11cf36b fix 2020-02-26 17:50:36 +04:00
Colombo
f1d115b63b added experimental face type 'whole_face'
Basic usage instruction: https://i.imgur.com/w7LkId2.jpg

	'whole_face' requires skill in Adobe After Effects.

	For using whole_face you have to extract whole_face's by using
	4) data_src extract whole_face
	and
	5) data_dst extract whole_face
	Images will be extracted in 512 resolution, so they can be used for regular full_face's and half_face's.

	'whole_face' covers whole area of face include forehead in training square,
	but training mask is still 'full_face'
	therefore it requires manual final masking and composing in Adobe After Effects.

added option 'masked_training'
	This option is available only for 'whole_face' type.
	Default is ON.
	Masked training clips training area to full_face mask,
	thus network will train the faces properly.
	When the face is trained enough, disable this option to train all area of the frame.
	Merge with 'raw-rgb' mode, then use Adobe After Effects to manually mask, tune color, and compose whole face include forehead.
2020-02-21 16:21:04 +04:00
Colombo
090d4a5be3 fix FANExtractor 2020-02-20 12:20:18 +04:00
Colombo
9598ba0141 SAEHD:
added option Eyes priority (y/n)

	fix eye problems during training  ( especially on HD architectures )
	by forcing the neural network to train eyes with higher priority
	before/after https://i.imgur.com/YQHOuSR.jpg

	It does not guarantee the right eye direction.
2020-02-18 14:30:07 +04:00
Colombo
4f928074b9 removing smooth_rect option 2020-02-18 10:28:01 +04:00
Colombo
814da70577 Merger:
added smooth_rect option
	default is ON.
	Decreases jitter of predicting rect by using temporal interpolation.
	You can disable this option if you have problems with dynamic scenes.
2020-02-17 18:27:09 +04:00
Colombo
60cc917350 add eye masking code 2020-02-03 06:38:58 +04:00
Colombo
5fe5fa131c SampleProcessor.py : refactoring and gen mask struct 2020-01-29 18:08:54 +04:00
Colombo
76ca79216e Upgraded to TF version 1.13.2
Removed the wait at first launch for most graphics cards.

Increased speed of training by 10-20%, but you have to retrain all models from scratch.

SAEHD:

added option 'use float16'
	Experimental option. Reduces the model size by half.
	Increases the speed of training.
	Decreases the accuracy of the model.
	The model may collapse or not train.
	Model may not learn the mask in large resolutions.

true_face_training option is replaced by
"True face power". 0.0000 .. 1.0
Experimental option. Discriminates the result face to be more like the src face. Higher value - stronger discrimination.
Comparison - https://i.imgur.com/czScS9q.png
2020-01-25 21:58:19 +04:00
Colombo
38b85108b3 DFL-2.0 initial branch commit 2020-01-21 18:43:39 +04:00
Colombo
47e539ccdd fix extract unaligned faces 2019-12-29 19:36:34 +04:00
Colombo
d46fb5cfd3 fixed mask editor
added FacesetEnhancer
4.2.other) data_src util faceset enhance best GPU.bat
4.2.other) data_src util faceset enhance multi GPU.bat

FacesetEnhancer greatly increases details in your source face set,
same as Gigapixel enhancer, but in fully automatic mode.
In OpenCL build it works on CPU only.

Please consider a donation.
2019-12-26 21:27:10 +04:00
Colombo
64021b9c62 more stable and precise version of face transformation matrix.
fixed bleeding mask on some samples
2019-12-20 10:30:49 +04:00
Colombo
068c7d0d55 temporary revert last fixes 2019-12-20 10:21:59 +04:00
Colombo
dd1d5e8909 improved face align,
More stable and precise version of the face transformation matrix.
Now full_faces are aligned with the upper and lateral boundaries of the frame,
result: fix of cutted mouth, increase area of the cheeks of side faces
before/after https://i.imgur.com/t9IyGZv.jpg
therefore, additional training is required for existing models.
Optionally, you can re-extract dst faces of your project, if they have problems with cutted mouth or cheeks.
2019-12-19 18:33:04 +04:00
Colombo
9e9dc364c9 temporary revert fix 2019-12-19 15:46:50 +04:00
Colombo
853a056769 more stable and precise version of face transformation matrix 2019-12-19 15:25:06 +04:00
Colombo
8035325f92 extractor: fix for amd 2019-10-27 12:47:12 +04:00
Colombo
75eeef0a96 fix for amd 2019-10-24 21:59:13 +04:00
Colombo
59d6fada23 draw up arrow in the red landmark debug square 2019-10-24 10:09:51 +04:00
Colombo
e63e89c305 fix s3fd extractor bug for 11GB+ cards 2019-10-17 22:25:23 +04:00
Colombo
5a2eefaa5b removed last fix 2019-10-14 20:31:11 +04:00
Colombo
e18b07549b new fix of "fixed bug when the same face could be detected twice" 2019-10-14 20:26:53 +04:00
Colombo
1de1e0029f Extractor now produces a less shaked face. but second pass is now slower by 25%,
before/after: https://imgur.com/L77puLH
2019-10-14 12:09:32 +04:00
Colombo
e013cb0f6b moving some files 2019-10-14 09:34:44 +04:00
Colombo
2b264da86b fixed bug when same face can be detected twice 2019-10-13 14:59:50 +04:00
Colombo
cbc18b2d41 nothing interesting 2019-10-06 17:55:32 +04:00
Colombo
d781af3d1f fixed GPU detection and indexes, got rid of using nvml, now using direct cuda lib to determine gpu info that match tensorflow indexes,
removed TrueFace model.

added SAEv2 model. Differences from SAE:
+ default e_ch_dims is now 21
+ new encoder produces more stable face and less scale jitter
  before: https://i.imgur.com/4jUcol8.gifv
  after:  https://i.imgur.com/lyiax49.gifv - scale of the face is less changed within frame size
+ decoder now has only 1 residual block instead of 2, result is same quality with less decoder size
+ added mid-full face, which covers 30% more area than half face.
+ added option " Enable 'true face' training "
  Enable it only after 50k iters, when the face is sharp enough.
  the result face will be more like src.
  The most src-like face with 'true-face-training' you can achieve with DF architecture.
2019-10-05 16:26:23 +04:00
Colombo
d9d10f91c2 S3FD and 2DFAN-4 were improperly ported from pytorch. now fixed. 2019-09-20 17:16:37 +04:00
Colombo
c06d073936 1 2019-09-19 11:16:35 +04:00