hanzhanggit / StackGAN

MIT License
1.86k stars 457 forks source link

Compatibility issue for python3 #2

Open Zardinality opened 7 years ago

Zardinality commented 7 years ago

I notice there is no requirement about python version in readme. But actually besides common import of print and absolute import from future, there are still some issues need to be resolved when I try to run the demo in python3. Including:

  1. I find relative path doesn't work wherever the directory I'm in. Is this alright in python2, or just because I use it in wrong way?

  2. Some string format problem, like caption in drawCaption and the pattern in save_super_images.

  3. dict.iteritem, dict.haskey method has been deprecated in python3, instead dict.items and in are used. So some code in config.py need to be modified.

  4. the result torchfile.load returns doesn't support access values through fetching attribute, like easydict. So I use [] ( e.g. t_file[b'raw_txt'] ) to access values, for a workaround.

  5. in drawCaption, fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 50) is used, but I have no clue where the font is, and it doesn't work with any luck. So I use a font in /usr/share/fonts/(Linux).

  6. xrange, in preprocess_birds.py.

At last I run the demo successfully, with a lot of temporary workaround, but I would prefer a indication about python version in the README.

hanzhanggit commented 7 years ago

Thanks. We use python 2.7 for the development. I will update README for this. If possible, maybe you can write all your workaround for python3 here. I think it will be helpful for the others. We really appreciate it.

Lotayou commented 6 years ago

Also there's another issue when try to retrain the network in Python 3. When you try to load a pickle object that was originally created in Python 2.x, it is most likely to trigger a UnicodeDecodeError:

UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 1: ordinal not in range(128)

The solution can be found here: GitHub: Unpickling a Python 2 object with Python 3

@hanzhanggit Can you update this in readme.md? Thanks!