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

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

Open
huaikaimancheng opened this issue Dec 2, 2022 · 1 comment
Open

Comments

@huaikaimancheng
Copy link

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
Copy link
Author

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

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

1 participant