yfeng95 / face3d

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

Issue about ValueError: Images of type float must be between -1 and 1 #32

Open FelixFox opened 5 years ago

FelixFox commented 5 years ago

I downloaded 300W-3D dataset which contains .jpg and corresponding .mat files. When I launch script in 8_generate_posmap_300WLP.py on this dataset, on some items I get following error (on the line of saving an image, representing uv position map): ValueError: Images of type float must be between -1 and 1

Why does it happen? I also tried to make values of such failing image by rerranging its values. It helps to save but saved uv position map image does not seem like uv position map: it's mostly black.

How to fix it?

FelixFox commented 5 years ago

Partly fixed it by deleting code which applies random perturbation to input data. Number of successed examples doubled :)

wqz960 commented 5 years ago

can you tell me how to fix it in detail, I am troubled in this problems! Thank you~!

FelixFox commented 5 years ago

@wqz960 in 8_generate_posmap_300WLP.py there are lines for applying random perturbation for data:

marg = old_size*0.1 t_x = np.random.rand()*marg*2 - marg t_y = np.random.rand()*marg*2 - marg center[0] = center[0]+t_x; center[1] = center[1]+t_y size = size*(np.random.rand()*0.2 + 0.9)

I just commented this. These lines modify parameters, which are used for cropping input image. Theoretically, these lines may be used for data augmentation.

wqz960 commented 5 years ago

Do you mean to delete these lines? I just viewed the code. the part seems to make data argument, if i delete that part, I will get the uv position map of the original image, is it what you mean? Thank you for your kind help!!! @FelixFox

wqz960 commented 5 years ago

@FelixFox Deleted these lines but also failed.

FelixFox commented 5 years ago

@wqz960 I also wrapped code in several functions and used try: except:. So some items of the dataset are processed and some not (the same error with ValueError). I can send you a modified version of the script which can be used on the whole dataset folder.

wqz960 commented 5 years ago

can you give me the script? my email is 362379625@qq.com! thank you very much! @FelixFox

wqz960 commented 5 years ago

@FelixFox I try your method. almost 60% images fail to process. ... :( what about your code?

pythonicrane commented 5 years ago

@wqz960 in 8_generate_posmap_300WLP.py there are lines for applying random perturbation for data:

marg = old_size*0.1 t_x = np.random.rand()*marg*2 - marg t_y = np.random.rand()*marg*2 - marg center[0] = center[0]+t_x; center[1] = center[1]+t_y size = size*(np.random.rand()*0.2 + 0.9)

I just commented this. These lines modify parameters, which are used for cropping input image. Theoretically, these lines may be used for data augmentation.

@wqz960 in 8_generate_posmap_300WLP.py there are lines for applying random perturbation for data:

marg = old_size*0.1 t_x = np.random.rand()*marg*2 - marg t_y = np.random.rand()*marg*2 - marg center[0] = center[0]+t_x; center[1] = center[1]+t_y size = size*(np.random.rand()*0.2 + 0.9)

I just commented this. These lines modify parameters, which are used for cropping input image. Theoretically, these lines may be used for data augmentation.

i just changed max(image_h, image_w) to max(image_h, image_w, np.max(uv_position_map)) i think it because of the rotation,some verties out of 256

gjd2017 commented 4 years ago

I have fixed this problem: use 'cv2.imwrite()' instead of 'io.imsave()'

Yingle1998 commented 3 years ago

Lossy conversion from float64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. Lossy conversion from float32 to uint8. Range [-7.8455047607421875, 101.833984375]. Convert image to uint8 prior to saving to suppress this warning. 4a8dfae0a1008aa87327b7b456317ee