NVlabs / stylegan3

Official PyTorch implementation of StyleGAN3
Other
6.3k stars 1.11k forks source link

generate_images raise Value Error: not enough image data?? #211

Open huaikaimancheng opened 1 year ago

huaikaimancheng commented 1 year ago

I am using my owner datasets to train a model by the stylegan3 code. The datasets are gray images. I have trained a model and want to use the generate_images file to generate samples. But it can't work when I run the code. The information is followed. error: Loading networks from "../input/afhqv2model/network-snapshot-000270.pkl"... Generating image for seed 0 (0/1) ... Setting up PyTorch plugin "bias_act_plugin"... Done. Setting up PyTorch plugin "filtered_lrelu_plugin"... Done. Traceback (most recent call last): File "../input/stylegan3pytorch/stylegan3-main/gen_images.py", line 143, in generate_images() # pylint: disable=no-value-for-parameter File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/opt/conda/lib/python3.7/site-packages/click/core.py", line 754, in invoke return __callback(args, **kwargs) File "../input/stylegan3pytorch/stylegan3-main/gen_images.py", line 137, in generate_images PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB').save(f'{outdir}/seed{seed:04d}.png') File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 2949, in fromarray return frombuffer(mode, size, obj, "raw", rawmode, 0, 1) File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 2876, in frombuffer return frombytes(mode, size, data, decoder_name, args) File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 2822, in frombytes im.frombytes(data, decoder_name, args) File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 831, in frombytes raise ValueError("not enough image data") ValueError: not enough image data What can I do about that? Thanks for helping me solve the problem.

huaikaimancheng commented 1 year ago

This problem has been done! The officially generate image code needs to be updated according to my own trained model. The following is my own modification.

#generate_images.py
…………………………………………………………………………………………
#img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
#PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB').save(f'{outdir}/seed{seed:04d}.png')
img = (img.permute(0, 1, 2, 3) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
PIL.Image.fromarray(img[0].cpu().numpy()[0]).save(f'{outdir}/seed{seed:04d}.png