zhixuhao / unet

unet for image segmentation
MIT License
4.6k stars 2k forks source link

Lossy conversion from float32 to uint8. Range [0, 1]. #125

Open IronLavender opened 5 years ago

IronLavender commented 5 years ago

Hello, is there anyone have this issue: Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. This information appears at the end of the execution result, a total of 30. But I have read the code, I fail to find where the "conversion from float32 to uint8" happens, so how can I solve this?

deaspo commented 5 years ago

Hello, is there anyone have this issue: Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. This information appears at the end of the execution result, a total of 30. But I have read the code, I fail to find where the "conversion from float32 to uint8" happens, so how can I solve this?

To address this warning, in the data.py file add the following import

from skimage import img_as_ubyte

And in the saveResult functionchange io. save function to

io.imsave(os.path.join(save_path,"%d_predict.png"%i),img_as_ubyte(img))

THe function img_as_ubyte does the conversion for you and you no longer have to see the warning. In addition update your skimage to the latest version, I think 0.15

IronLavender commented 5 years ago

Hello, is there anyone have this issue: Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. This information appears at the end of the execution result, a total of 30. But I have read the code, I fail to find where the "conversion from float32 to uint8" happens, so how can I solve this?

To address this warning, in the data.py file add the following import

from skimage import img_as_ubyte

And in the saveResult functionchange io. save function to

io.imsave(os.path.join(save_path,"%d_predict.png"%i),img_as_ubyte(img))

THe function img_as_ubyte does the conversion for you and you no longer have to see the warning. In addition update your skimage to the latest version, I think 0.15

Thank you so much! This problem has been solved by your help.

lloydjie1 commented 4 years ago

I am getting gray images even after the adjustments. Can anyone suggest a solution?

deaspo commented 4 years ago

I am getting gray images even after the adjustments. Can anyone suggest a solution?

What is the COLOR_DICT you use when writing the images?

lloydjie1 commented 4 years ago

Hi I wonder in which python file shall we look for the COLOR_DICT?

sdp369 commented 4 years ago

img_as_ubyte(img)

UserWarning: C:/Users/sdp/Desktop/images\1_predict.png is a low contrast image io.imsave(os.path.join(save_path,"%d_predict.png"%i),img_as_ubyte(img))

please help

tsorewilly commented 4 years ago

I am getting gray images even after the adjustments. Can anyone suggest a solution?

What is the COLOR_DICT you use when writing the images?

@deaspo did you solve this problem, I have similar challenge and I am unable to resolve it. Did anyone have insight into why?

Help(s) would be appreciated. @zhixuhao @IronLavender @lloydjie1 @sdp369

deaspo commented 4 years ago

I am getting gray images even after the adjustments. Can anyone suggest a solution?

What is the COLOR_DICT you use when writing the images?

@deaspo did you solve this problem, I have similar challenge and I am unable to resolve it. Did anyone have insight into why?

Help(s) would be appreciated. @zhixuhao @IronLavender @lloydjie1 @sdp369

The COLOR_DICT is defined here --> COLOR_DICT

If still getting the error, maybe because training was insufficient (try change of parameters) or save in different format that accepts floats i.e. tif --> io.imsave(os.path.join(save_path,"%d_predict.tif"%i),img_as_float(img))

chen-chunling commented 3 years ago

img_as_ubyte(img)

UserWarning: C:/Users/sdp/Desktop/images\1_predict.png is a low contrast image io.imsave(os.path.join(save_path,"%d_predict.png"%i),img_as_ubyte(img))

please help

Have you solved this problem? I have the similar problem with you.

deaspo commented 3 years ago

img_as_ubyte(img)

UserWarning: C:/Users/sdp/Desktop/images\1_predict.png is a low contrast image io.imsave(os.path.join(save_path,"%d_predict.png"%i),img_as_ubyte(img)) please help

Have you solved this problem? I have the similar problem with you.

Alternative try saving in a different format and check the output images. If the are still black try playing with the model settings until the loss is reducing. If you are using your own images and labels, may need to recheck them again. Also update the skimage package. The warning might not be the problem, could be any of the other things mentioned.

deaspo commented 3 years ago

I have created a Collab notebook of this repo. Change line 55 in models.py to model = Model(inputs = inputs, outputs = conv10) The same warnings are there but the output looks resonable. The problem might because you are using different input images and you need to change model params when training. Or update skimage

chen-chunling commented 3 years ago

I have created a Collab notebook of this repo. Change line 55 in models.py to model = Model(inputs = inputs, outputs = conv10) The same warnings are there but the output looks resonable. The problem might because you are using different input images and you need to change model params when training. Or update skimage

Thank you for such a detailed reply! I am a beginner, so I don’t know if the program runs successfully at first. I have changed line 55 in models.py as yours, and now I know it runs successfully and the warning is not the problem. I appreciate for your help! :) @deaspo

GalangZero13 commented 3 years ago

Has tried changing the format, gonna try changing params next. Does anyone has a sure go params to try to use it with its initial datasets? what changes of params should I made if I want to have result with the membrane datasets? Because I'm going to try it with my own datasets of traffic sign next.

Thunder003 commented 3 years ago

@deaspo do you have any idea why due to a change in the data type (done by skimage automatically) of the image while saving is showing a black image? As from img_as_ubyte, we are also doing the same thing, just prior to saving we are doing it manually.