yfeng95 / face3d

Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.
2.65k stars 611 forks source link

ValueError: Images of type float must be between -1 and 1 #28

Open danindiana opened 5 years ago

danindiana commented 5 years ago

When trying to run example 7_generate_uv_map.py I get an error:

$python 7_generate_uv_map.py Traceback (most recent call last): File "7_generate_uv_map.py", line 50, in io.imsave('{}/uv_texture_map.jpg'.format(save_folder), np.squeeze(uv_texture_map)) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 143, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, *plugin_args) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 214, in call_plugin return func(args, **kwargs) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 259, in imsave img = ndarray_to_pil(arr, format_str=format_str) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 163, in ndarray_to_pil arr = img_as_ubyte(arr) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte return convert(image, np.uint8, force_copy) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1.

Might be related to this topic: http://scikit-image.org/docs/stable/user_guide/data_types.html

and this thread appears to be dealing with same issue: https://github.com/scikit-image/scikit-image/issues/2756

image

HectorAnadon commented 5 years ago

What scikit-image version do you have? I have 0.14.0 and it is working fine for me.

FelixFox commented 5 years ago

I have scikit-image ver. 0.14.0 and it still does not work. The same error.

I also tried to change the range of values of uv_position_map to (0,1) and (-1,-1) or even (0,255).

Output image almost the same in these 3 cases: ibug_image_008_1_0_posmap

FelixFox commented 5 years ago

Issue resolved! You should change uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/stn/BFM_UV.mat') to uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/Out/BFM_UV.mat')

HectorAnadon commented 5 years ago

But it is like that https://github.com/YadiraF/face3d/blob/master/examples/7_generate_uv_map.py#L36

FelixFox commented 5 years ago

But it is like that https://github.com/YadiraF/face3d/blob/master/examples/7_generate_uv_map.py#L36

As I understood, script in 7_generate_uv_map.py loads 3d model from example1.mat file with its vertices and colors and creates from it a uv-position map. At the same time it creates from it 2d image and uv-texture map.

And script in 8_generate_posmap_300WLP.py uses an example from 300W_LP dataset (more precisely, .mat file from this) to generate uv-position map .

In these both scripts BFM_UV.mat is used in order to generate uv-position map. First, it is processed in process_uv() and then the result is used in mesh.render.render_colors() function. You can see what happens inside by looking here (What happens here I don't understand completely :) ).

So, If I undestand correctly, these both scripts do almost the same thing in context of uv-position map :)

vastyao commented 5 years ago

When trying to run example 7_generate_uv_map.py I get an error:

$python 7_generate_uv_map.py Traceback (most recent call last): File "7_generate_uv_map.py", line 50, in io.imsave('{}/uv_texture_map.jpg'.format(save_folder), np.squeeze(uv_texture_map)) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 143, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, *plugin_args) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 214, in call_plugin return func(args, **kwargs) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 259, in imsave img = ndarray_to_pil(arr, format_str=format_str) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/io/_plugins/pil_plugin.py", line 163, in ndarray_to_pil arr = img_as_ubyte(arr) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte return convert(image, np.uint8, force_copy) File "/home/johnh/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1.

Might be related to this topic: http://scikit-image.org/docs/stable/user_guide/data_types.html

and this thread appears to be dealing with same issue: scikit-image/scikit-image#2756

image

I have meet the same question, how did you solve it? The method is mentioned don't work for me.

douyh commented 4 years ago

Issue resolved! You should change uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/stn/BFM_UV.mat') to uv_coords = face3d.morphable_model.load.load_uv_coords('./Data/BFM/Out/BFM_UV.mat')

I don't have matlab on my computer and I don't have the access to install either. Could you give me a copy of Out/BFM_UV.mat