seasonSH / SemanticStyleGAN

release code for SemanticStyleGAN (CVPR 2022)
https://semanticstylegan.github.io/
261 stars 32 forks source link

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fd3aa7f1900> #8

Open diamond0910 opened 2 years ago

diamond0910 commented 2 years ago

I train this repo and get an error after 6900 iterations.

[006300] d: 0.7976; g: 1.3474; real: 0.7283; fake: -2.8740; r1_img: 0.0032; r1_seg: 0.0002; path: 0.0103; mean path: 0.3067; mask: 0.0009; time: 1.83
[006400] d: 0.9274; g: 0.9121; real: 0.7363; fake: -1.7912; r1_img: 0.0036; r1_seg: 0.0001; path: 0.0092; mean path: 0.3107; mask: 0.0010; time: 2.76
[006500] d: 0.9621; g: 1.2088; real: 0.8927; fake: -0.4084; r1_img: 0.0002; r1_seg: 0.0000; path: 0.0105; mean path: 0.3139; mask: 0.0008; time: 1.76 [006600] d: 0.8269; g: 2.4908; real: 2.9391; fake: -0.2358; r1_img: 0.0044; r1_seg: 0.0004; path: 0.0180; mean path: 0.3148; mask: 0.0010; time: 1.76 [006700] d: 0.8173; g: 1.1811; real: 0.4405; fake: -1.5368; r1_img: 0.0010; r1_seg: 0.0001; path: 0.0590; mean path: 0.3165; mask: 0.0014; time: 1.75 [006800] d: 0.7892; g: 1.3737; real: 1.1018; fake: -0.9716; r1_img: 0.0025; r1_seg: 0.0001; path: 0.0059; mean path: 0.3166; mask: 0.0008; time: 2.75 [006900] d: 0.9794; g: 1.7224; real: 0.8551; fake: -0.3744; r1_img: 0.0039; r1_seg: 0.0001; path: 0.0175; mean path: 0.3235; mask: 0.0009; time: 1.74 Traceback (most recent call last):
File "train.py", line 518, in
train(args, ckpt_dir, loader, generator, discriminator, g_optim, d_optim, g_ema, device, writer)
File "train.py", line 199, in train
real_data = next(loader)
File "train.py", line 76, in sample_data
for batch in loader:
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 530, in next
data = self._next_data()
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1224, in _next_data
return self._process_data(data)
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1250, in _process_data
data.reraise()
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/_utils.py", line 457, in reraise
raise exception
PIL.UnidentifiedImageError: Caught UnidentifiedImageError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/data/zwy/research/SemanticStyleGAN/utils/dataset.py", line 87, in getitem
img = Image.open(BytesIO(txn.get(f'image-{str(idx).zfill(7)}'.encode('utf-8')))).convert('RGB')
File "/mnt/disk/zwy/miniconda3/envs/ssgan/lib/python3.8/site-packages/PIL/Image.py", line 3147, in open
"""
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f395679f9f0>

Here is my package's version.

Pillow 8.3.1 pip 22.1.2 protobuf 3.19.4 psutil 5.9.1 py-bt 1.2.1 pyasn1 0.4.8 pyasn1-modules 0.2.8 PyOpenGL 3.1.5 pyparsing 3.0.9 pyrsistent 0.18.1 PySocks 1.7.1 pyspng 0.1.0 python-dateutil 2.8.2 PyWavelets 1.3.0 PyYAML 6.0 qudida 0.0.4 requests 2.26.0 requests-oauthlib 1.3.1 rsa 4.8 scikit-image 0.19.3 scikit-learn 1.1.1 scipy 1.7.1 setuptools 61.2.0 Shapely 1.8.2 six 1.16.0 soupsieve 2.3.2.post1 tensorboard 2.9.1 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.1 threadpoolctl 3.1.0 tifffile 2022.5.4 torch 1.11.0+cu113 torchvision 0.12.0+cu113 tqdm 4.62.2 typing_extensions 4.3.0 urllib3 1.26.10 Werkzeug 2.1.2 wheel 0.37.1 zipp 3.8.1

What is the problem? Thank you!

seasonSH commented 2 years ago

Seems like some images are not correctly encoded when creating the LMDB dataset. Please make sure that all files under your dataset folder are valid image files when making the LMDB.