Prinsphield / GeneGAN

GeneGAN: Learning Object Transfiguration and Attribute Subspace from Unpaired Data
https://arxiv.org/abs/1705.04932v1
GNU General Public License v3.0
144 stars 34 forks source link

python version #1

Closed lizhuorong closed 6 years ago

lizhuorong commented 7 years ago

Hi, thanks for sharing the awesome codes! I have a problem with the codes in python3. It will report an error pointing at the line 150 of preprocess.py as python 2.7 does not support the function "pool.starmap". When I switch to python3, I cannot import CV2! I am new to python and I failed so many times to make the codes adapt to python2.7. Do you know how to rewrite line 150 ? I deeply appreciate your sharing and look forward to your help. Thanks!

Prinsphield commented 7 years ago

Since python2 does not support starmap, so you have to use map instead. In this way, only one parameter can be passed into map. So you need to define these freeze parameters data_dir, out_dir, landmarks in the work function. Add these lines in work function may work: data_dir = ... out_dir = ... landmarks = ...

Alternatively, you can use functools.partial for passing several parameters in map.

lizhuorong commented 7 years ago

Thanks a lot for your quick reply!

I add these lines in the "work" function: data_dir = 'home/lzr/Documents/datasets/celebA' out_dir = './dataset/celebA/align_5p/' As for the "landmarks =", do you suggest that a directory or the file name of it?

Beside the augment above, I replace the 'pool.starmap' function with "pool.map" and no other args are changed. Am I correctly get what you mean? If not, would you show me in a specific way?

Thanks again!

lizhuorong commented 7 years ago

def work(i): data_dir = '/home/lzr/Documents/gan/datasets/celebA/' out_dir = './datasets/celebA/align_5p/' with open(os.path.join(data_dir, 'list_landmarks_celeba.txt'), 'r') as f: landmarks = [list(map(int, x.split()[1:11])) for x in f.read().strip().split('\n')[2:]]

src_imname = os.path.join(data_dir, 'data', '{:06d}.jpg'.format(i+1))
des_imname = os.path.join(out_dir, '{:06d}.jpg'.format(i+1))
img = cv2.imread(src_imname)
aligned_img = align_face_5p(img, landmarks[i])
cv2.imwrite(des_imname, aligned_img)
return 0

Besides I replace the starmap with: pool.map(work, range(len(im_list)))

Am I correctly get what you mean? However, errors occur as followed: File "preprocess.py", line 174, in main('/home/lzr/Documents/gan/datasets/celebA/', './datasets/celebA/align_5p/', 30)
File "preprocess.py", line 167, in main pool.map(work, range(len(im_list))) File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value cv2.error: /home/lzr/Downloads/opencv-2.4.13.2/modules/imgproc/src/imgwarp.cpp:3591: error: (-215) src.cols > 0 && src.rows > 0 in function warpAffine

Could you help me out of trouble?

Besides, I think the formula (4) in the paper is wrong as the A0 and B0 are in reverse. Please think about it and tell me the right one. Thanks!

Prinsphield commented 7 years ago

Actually, I changed codes as I said above, no problem occurred! Check your dataset again. Please run identify datasets/celebA/data/000001.jpg. The size should be 409 x 687 if you are using the same dataset.

Thanks for pointing out the mistake in that formula. We will correct it in the published version.

Prinsphield commented 7 years ago

I have committed again. You can git pull and try again.