Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to load network .pkl file #6

Open
Baoren1996 opened this issue Sep 3, 2024 · 5 comments
Open

Fail to load network .pkl file #6

Baoren1996 opened this issue Sep 3, 2024 · 5 comments

Comments

@Baoren1996
Copy link

Baoren1996 commented Sep 3, 2024

I tried to download the saved network from the link below:
https://zenodo.org/record/10947091/files/stylesan-xl_cifar10.pkl
however, when I tried to use the following code for evaluation:

python calc_metrics.py --metrics=fid50k_full --network=./stylesan-xl_cifar10.pkl

but got error:
Screenshot 2024-09-03 at 12 03 00

Python==3.8.10
Pytorch==2.4.0+cu121

Can somebody help?

@TakashiShibuyaSony
Copy link
Collaborator

Hello, thank you for reaching out to us!

Our recommendation is preparing a Docker container, following the README.md.
https://github.com/sony/san/tree/main/stylesan-xl#requirements

If you don't want to rely on Docker for some reason, it should be good to use the same versions of packages described in the following files.

numpy>=1.20
click>=8.0
pillow>=8.3.1
scipy>=1.7.1
requests>=2.26.0
tqdm>=4.62.2
ninja>=1.10.2
matplotlib>=3.4.2
imageio>=2.9.0
dill>=0.3.4
psutil>=5.8.0
regex>=2022.3.15
pillow>=8.3.1
imgui>=1.3.0
glfw>=2.2.0
pyopengl>=3.1.5
imageio-ffmpeg>=0.4.3
pyspng
ftfy>=6.1.1
timm==0.4.12

RUN pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu121

This may work.

Thank you.

@Baoren1996
Copy link
Author

Hello, thank you for reaching out to us!

Our recommendation is preparing a Docker container, following the README.md. https://github.com/sony/san/tree/main/stylesan-xl#requirements

If you don't want to rely on Docker for some reason, it should be good to use the same versions of packages described in the following files.

numpy>=1.20
click>=8.0
pillow>=8.3.1
scipy>=1.7.1
requests>=2.26.0
tqdm>=4.62.2
ninja>=1.10.2
matplotlib>=3.4.2
imageio>=2.9.0
dill>=0.3.4
psutil>=5.8.0
regex>=2022.3.15
pillow>=8.3.1
imgui>=1.3.0
glfw>=2.2.0
pyopengl>=3.1.5
imageio-ffmpeg>=0.4.3
pyspng
ftfy>=6.1.1
timm==0.4.12

RUN pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu121

This may work.
Thank you.

Hi @TakashiShibuyaSony, thanks for your instruction which works perfectly for me.

Another question, given the CIFAR model snapshot, is there any way to resume the training from the pkl file? do I also need the stem network .pkl file?

Thanks a lot in advance.

Best,
Baoren

@TakashiShibuyaSony
Copy link
Collaborator

TakashiShibuyaSony commented Sep 8, 2024

Hi @Baoren1996,
You can resume the training by using the following option. You should provide the path of the .pkl file.

@click.option('--resume', help='Resume from given network pickle', metavar='[PATH|URL]', type=str)

Regarding the .pkl file of the stem network, the current code requires it (Our codebase build on that of StyleGAN-XL, and their code requires a stem network even in resuming training). But, I guess you can resume the training without the stem network by reloading the ckpt for resume in the following lines again.

with dnnlib.util.open_url(path_stem) as f:
G_stem = legacy.load_network_pkl(f)['G_ema']

And, the succeeding lines should also be modified. In particular, the following lines are not necessary in this case because these lines are for appending new layers in progressive training.
# initialize new_layers
last_stem_layer = getattr(self.synthesis, self.synthesis.layer_names[-1])
fparams = self.compute_superres_filterparams(up_factor, self.img_resolution, last_stem_layer, head_layers)
self.head_layer_names = []
for idx in range(head_layers + 1):
prev = max(idx - 1, 0)
is_torgb = (idx == head_layers)
is_critically_sampled = (idx >= head_layers - self.num_critical)
use_fp16 = (fparams.sampling_rates[idx] * (2 ** self.num_fp16_res) > self.img_resolution)
layer = SynthesisLayer(
w_dim=self.w_dim, is_torgb=is_torgb, is_critically_sampled=is_critically_sampled, use_fp16=use_fp16,
in_channels=int(fparams.channels[prev]), out_channels= int(fparams.channels[idx]),
in_size=int(fparams.sizes[prev]), out_size=int(fparams.sizes[idx]),
in_sampling_rate=int(fparams.sampling_rates[prev]), out_sampling_rate=int(fparams.sampling_rates[idx]),
in_cutoff=fparams.cutoffs[prev], out_cutoff=fparams.cutoffs[idx],
in_half_width=fparams.half_widths[prev], out_half_width=fparams.half_widths[idx],
conv_kernel=self.conv_kernel, use_radial_filters=self.use_radial_filters,
)
name = f'L{idx+stem_len}_{layer.out_size[0]}_{layer.out_channels}'
setattr(self.synthesis, name, layer)
self.synthesis.layer_names.append(name)
self.head_layer_names.append(name)

Thanks!

@Cwyxx
Copy link

Cwyxx commented Oct 9, 2024

Update dill to 0.3.9. It works for me.

@TakashiShibuyaSony
Copy link
Collaborator

Hi @Cwyxx, Thank you very much for your helpful information. We updated requirements.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants