'stylegan3 stylegan2-ada tensor mismatch error for every 256 or 512 flickr related model

Anyone having the same tensor size mismatch when trying finetuning on ffhq,ffhqu or celebahq models with stylegan3 (and with --cfg=stylegan2)?

With afhqv2 and metfaces I had no problems at 512 and 1048 sizes.

Error:

...
File "/home/ubuntu/stylegan3/training/training_loop.py", line 162, in training_loop
    misc.copy_params_and_buffers(resume_data[name], module, require_all=False)
  File "/home/ubuntu/stylegan3/torch_utils/misc.py", line 162, in copy_params_and_buffers
    tensor.copy_(src_tensors[name].detach()).requires_grad_(tensor.requires_grad)

RuntimeError: The size of tensor a (512) must match the size of tensor b (256) at non-singleton dimension 0

example command:

python "train.py" --outdir=training-runs --cfg=stylegan3-r --data="datasets/256.zip" --gpus=1 --batch=16 --batch-gpu=16 --gamma=6.6 --mirror=1 --kimg=2 --snap=5  --resume=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-ffhqu-256x256.pkl

I've verified I was passing 256 images built with the tool:

python dataset_tool.py --source="img/" --dest="datasets/256.zip" --resolution='256x256'

Note: I was able to finetune only with this version stylegan2-ffhq-512x512.pkl



Solution 1:[1]

(I have found a fix! Look at the end of this answer) Yes, I cannot train my 256x256 dataset. I get :

RuntimeError: The size of tensor a (256) must match the size of tensor b (128) at non-singleton dimension 1

After I run:

!python /content/drive/MyDrive/WIP/stylegan3/train.py --outdir=~/training-runs --cfg=stylegan3-r --data=/content/drive/MyDrive/WIP/stylegan3/datasets/halves-256x256.zip \
    --gpus=1 --batch=32 --batch-gpu=8 --gamma=2 --mirror=1 --kimg=500 --snap=2 --metrics=none \
    --resume=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-ffhqu-256x256.pkl

The FIX

If you are trying to do transfer learning on "stylegan3-r-ffhqu-256x256.pkl", you should add

--cbase=16384

in your command

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1