Page 1 of 1

NaN while training, then invalid value encountered in rint patched_face = np.rint(patched_face,

Posted: Sat Mar 20, 2021 1:58 pm
by Diego427

Hello

After it trained for seven hours I left it going on for the night, but it ended up having NaN errors and a black rectangle instead of the face on the preview... :o
I tried to convert anyway, but it says :
faceswap\lib\convert.py:197: RuntimeWarning: invalid value encountered in rint
patched_face = np.rint(patched_face,

Is there a way to have FaceSwap ignore the bad corrupt data and convert using only the good data ?

Thanks


Re: NaN while training, then invalid value encountered in rint patched_face = np.rint(patched_face,

Posted: Sat Mar 20, 2021 4:25 pm
by torzdf

Sadly not.

Ultimately, if a NaN occurs in the model, your model is effectively dead. That one NaN will start propagating out to other weights and ultimately the model will collapse and fail.

I have recently (read: yesterday) added NaN protection for training. This will not solve your current issue, unfortunately (you'll need to roll-back to a pre NaN snapshot/backup). But in future, make sure it's enabled and if a NaN is encountered then the model will halt immediately. Your last save should be NaN free, and sometimes it's as simple as just kicking off training again.


Re: NaN while training, then invalid value encountered in rint patched_face = np.rint(patched_face,

Posted: Sat Mar 20, 2021 4:52 pm
by Diego427

Ok, too bad. :cry:
It made an auto snapshot at 25.000 but I tried to load it and it was already corrupt.
Maybe I can share my logs to help you find bugs or something ?
By the way, I was training in Lighweight mode on the CPU ( Ryzen 5 3600 + 32GB DDR4 ), for my graphic card is too old and incompatible (9500GT from 2008 :oops:). Maybe that explains the bug.


Re: NaN while training, then invalid value encountered in rint patched_face = np.rint(patched_face,

Posted: Sat Mar 20, 2021 4:54 pm
by torzdf

Unfortunately NaNs can happen on any model (although some are more susceptible than others).

Training a model is "unbounded" which means that it is possible for a weight update to occur outside of the numerical range that a datatype (specifically float32) can hold. This can happen for numerous reasons and there isn't much you can do to protect against it.


error when converting or preview

Posted: Sun Mar 21, 2021 1:34 am
by 230V

how to understand this log?

Loading...
Setting Faceswap backend to AMD
03/21/2021 02:22:13 INFO Log level set to: INFO
03/21/2021 02:22:14 INFO Setting up for PlaidML
03/21/2021 02:22:14 INFO Using GPU(s): ['Advanced Micro Devices, Inc. - Ellesmere (experimental)', 'Advanced Micro Devices, Inc. - Ellesmere (supported)']
03/21/2021 02:22:14 INFO Successfully set up for PlaidML

03/21/2021 02:22:16 INFO Reading alignments from: 'C:\fs\convert\edit_alignments.fsa'
03/21/2021 02:22:16 INFO Loading Writer from Opencv plugin...

Using plaidml.keras.backend backend.
03/21/2021 02:22:16 INFO Using configuration saved in state file
03/21/2021 02:22:16 INFO Opening device "opencl_amd_ellesmere.0"
03/21/2021 02:22:17 INFO Loaded model from disk: 'C:\fs\convert\edit\MODEL\original.h5'
03/21/2021 02:22:17 INFO Loading Mask from Box_Blend plugin...
03/21/2021 02:22:17 INFO Loading Mask from Mask_Blend plugin...
03/21/2021 02:22:17 INFO Loading Color from Avg_Color plugin...
03/21/2021 02:22:17 INFO Loading Scaling from Sharpen plugin...
C:\Users\fs\faceswap_amd\plugins\convert\color\avg_color.py:16: RuntimeWarning: invalid value encountered in true_divide
adjustment = avg_diff / np.sum(raw_mask, axis=(0, 1))
C:\Users\fs\faceswap_amd\plugins\convert\scaling\sharpen.py:57: RuntimeWarning: invalid value encountered in less
low_contrast_mask = (abs(new_face - blur) < threshold).astype("float32")
C:\Users\fs\faceswap_amd\lib\convert.py:197: RuntimeWarning: invalid value encountered in rint
patched_face = np.rint(patched_face,

Terminating Process...
Terminated
Process exited.


Re: error when converting or preview

Posted: Sun Mar 21, 2021 12:59 pm
by torzdf

Does this happen immediately, or several faces into your convert?


Re: error when converting or preview

Posted: Sun Mar 21, 2021 1:15 pm
by 230V

it happens immediately and shoots out frames without faces (black squares where the swapface should be)


Re: error when converting or preview

Posted: Sun Mar 21, 2021 1:15 pm
by torzdf

Ok. So most likely there is a "NaN" in your model. I'm merging this topic with a similar discussion....