faceswap icon indicating copy to clipboard operation
faceswap copied to clipboard

GPU training does not work

Open MarcSN311 opened this issue 8 years ago • 13 comments

Limit:                  1823465472
InUse:                  1823465472
MaxInUse:               1823465472
NumAllocs:                     229
MaxAllocSize:             94452992

2018-01-28 16:25:05.010972: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:277] ***************************************************************************************************x
2018-01-28 16:25:05.011266: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\framework\op_kernel.cc:1192] Resource exhausted: OOM when allocating tensor with shape[2048]```

## Other relevant information

- **Operating system and version:** Windows 8.1
- **Python version:** 3.6.4
- **Faceswap version:** a799f769e4c48908c3efd64792384403392f2e82
- **Faceswap method:** GPU

MarcSN311 avatar Jan 28 '18 15:01 MarcSN311

Your GPU does not have enough memory. Try decreasing ENCODER_DIM to 512.

rifterbater avatar Jan 28 '18 16:01 rifterbater

tried tuning ENCODER_DIM and BATCH_SIZE. did not find a working combination. For ENCODER_DIM=64 and BATCH_SIZE=1 i get one valid output 0.15305635 0.11783895 but then it just says save model weights and quits.

2018-01-28 20:05:43.939681: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this T
ensorFlow binary was not compiled to use: AVX
2018-01-28 20:05:44.539616: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties:
name: Quadro K2000M major: 3 minor: 0 memoryClockRate(GHz): 0.745
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.92GiB
2018-01-28 20:05:44.540210: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GP
U:0) -> (device: 0, name: Quadro K2000M, pci bus id: 0000:01:00.0, compute capability: 3.0)
2018-01-28 20:05:47.504003: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.14GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:47.566201: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.07GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:47.603648: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.04GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:47.730635: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.04GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:47.838415: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.03GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:47.860781: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.07GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:48.012480: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:48.050733: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.14GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:48.051200: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 2.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
2018-01-28 20:05:48.108983: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\bfc_allocator.cc:217] Allocator (GPU_0_bfc) ran out of memory
trying to allocate 1.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
0.15305635 0.11783895
save model weights
usage: faceswap.py [-h] {extract,train,convert} ...

positional arguments:
  {extract,train,convert}
    extract             Extract the faces from a pictures.
    train               This command trains the model for the two faces A and
                        B.
    convert             Convert a source image to a new one with the face
                        swapped.

optional arguments:
  -h, --help            show this help message and exit

MarcSN311 avatar Jan 28 '18 19:01 MarcSN311

Setting batch size <14 can screw up the preview window which is hard-coded to display a bunch of preview images. It's possible to edit that too and run 1 sized batches but it's kind of a pain.

How much memory does your GPU have? 64 is really low for ENCODER_DIM, probably going to have a hard time getting good results.

rifterbater avatar Jan 28 '18 19:01 rifterbater

I did not enable the preview window. It's just 2 GB memory. Just wanted to have a look at this!

MarcSN311 avatar Jan 28 '18 19:01 MarcSN311

Did you figured it out? Because i have 2GB card too and im facing ran out of memory error too.

shadowzoom avatar Jan 30 '18 05:01 shadowzoom

there are 4GB memory in my GPU, but I also had the same error

duoyu5555 avatar Jan 30 '18 07:01 duoyu5555

Had the same with 4GB GPU

I edited ENCODER_DIM to 512 in model.py and it works for me. Iterations are 20x faster on GPU now.

see also https://github.com/deepfakes/faceswap/issues/40#issuecomment-354393545

schmunk42 avatar Jan 30 '18 14:01 schmunk42

Also there is a LowMem model plugin now. You can edit scripts/convert.py and replace "Original in "variant = "Original" with "LowMem". But be careful, as it has one layer less, your current model will not be reloaded if you started training it!

Clorr avatar Jan 31 '18 18:01 Clorr

I've a NVIDIA GeForce 940MX with 2GB dedicated VRAM.

I edited ENCODER_DIM in Model_LowMem.py to 128 (it represents nodes of NN?) and commented line

#x = self.conv(512)(x) (layers of NN?)

It works for me.

Could be useful to add CLI parameters for ENCODER_DIM and convolutions.

lnora avatar Feb 01 '18 19:02 lnora

I'm not much in favor of adding CLI params for that, because if you later provide incorrect params, you may well end up with unusable model files. They are not parameters in the sense you can change them freely from time to time, they are intrinsic to the model that is trained.

Clorr avatar Feb 02 '18 11:02 Clorr

If you train with LowMem you will also need to use the LowMem model when converting. If not you will get a layer count mismatch.

I could see a todo in the code so have put a pull request in to fix this. Hope that is OK. Please just disregard if not :)

facepainter avatar Feb 02 '18 16:02 facepainter

Any pull request is welcome ;-)

Clorr avatar Feb 02 '18 17:02 Clorr

@MarcSN311 has this solved your problem?

gdunstone avatar Feb 07 '18 16:02 gdunstone