yfeng95 / PRNet

Joint 3D Face Reconstruction and Dense Alignment with Position Map Regression Network (ECCV 2018)
http://openaccess.thecvf.com/content_ECCV_2018/papers/Yao_Feng_Joint_3D_Face_ECCV_2018_paper.pdf
MIT License
4.95k stars 947 forks source link

python 3 compatibility #23

Open kylemcdonald opened 6 years ago

kylemcdonald commented 6 years ago

it would be great to make this compatible with python 3!

i mentioned a problem in https://github.com/YadiraF/PRNet/issues/21 but wanted to start a fresh issue here.

$ python run_basics.py 
2018-05-01 12:16:47.603620: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1349] Found device 0 with properties: 
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6575
pciBusID: 0000:05:00.0
totalMemory: 10.91GiB freeMemory: 8.34GiB
2018-05-01 12:16:47.603651: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1428] Adding visible gpu devices: 0
2018-05-01 12:16:47.806106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-05-01 12:16:47.806140: I tensorflow/core/common_runtime/gpu/gpu_device.cc:922]      0 
2018-05-01 12:16:47.806148: I tensorflow/core/common_runtime/gpu/gpu_device.cc:935] 0:   N 
2018-05-01 12:16:47.806319: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1046] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 8060 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:05:00.0, compute capability: 6.1)
2018-05-01 12:16:47.807380: I tensorflow/core/common_runtime/process_util.cc:64] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
Traceback (most recent call last):
  File "run_basics.py", line 52, in <module>
    write_obj(os.path.join(save_folder, name + '.obj'), vertices, colors, prn.triangles) #save 3d face(can open with meshlab)
  File "/home/kyle/Documents/PRNet/utils/write.py", line 37, in write_obj
    f.write(s)
TypeError: a bytes-like object is required, not 'str'
yfeng95 commented 6 years ago

Hi, thanks for your reporting! This problem like https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa.

So please try to changeopen(obj_name, 'wb') to open(obj_name, 'w') or open(obj_name, 'wt').

My env is python 2 now, so I haven't verified this method. Please tell me whether this can solve.

And, it seems @cclauss also uses python 3, can you please help me solve this issue?

983 commented 6 years ago

run_basics.py worked for me after changing the 'wb' to 'w' in 3 places:

https://github.com/YadiraF/PRNet/blob/master/utils/write.py#L31 https://github.com/YadiraF/PRNet/blob/master/utils/write.py#L66 https://github.com/YadiraF/PRNet/blob/master/utils/write.py#L89

Additionally, I had to create the directory AFLW2000 in TestImages/AFLW2000_results to get TestImages/AFLW2000_results/AFLW2000.

awilliamson commented 6 years ago

Standard 2to3 write on everything works bar the bytes-str issue. Either do str.encode('utf-8') and b"my string" or as @YadiraF suggests by removing byte writing mode ( more sensible ). I have this working under Python 3 environment.

alain2208 commented 6 years ago

I had some issues in python 3 with the path but I think it's more coming from Windows where I have problem with not complete path and also / and \ in path

cclauss commented 6 years ago

@alain2208 Windows path issues can usually be solved with judicious use of os.path.join() and/or os.sep. If you could please open a pull requests or at least an issue, that would help.

cclauss commented 6 years ago

Is this issue still open?