Open matheuscass opened 6 years ago
Same problem, did you find a solution?
You can see here:https://github.com/ShawDa/unet-rgb
i) in your model.py
input_size (256,256,1) => (256,256,3)
ii) trainGenerator function in your data.py
image_color_mode ="grayscale"=>"rgb"
iii) testGenerator function in your data.py
comment out "img = np.reshape(img,img.shape+(1,)) if (not flag_multi_class) else img"
Hi @teamo429 ,
I tried to use your method to train model and predict the rpg image, however, all of predict image are black... do you know how to resolve it?
Hi @teamo429 ,
I tried to use your method to train model and predict the rpg image, however, all of predict image are black... do you know how to resolve it?
did you resolve it
If anyone still has this issue with reading RGB images or getting errors please look for me. Went through the same and found a fix for ti
If anyone still has this issue with reading RGB images or getting errors please look for me. Went through the same and found a fix for ti
Can you please tell how did you solve this issue. I am getting all white images as output.
If anyone still has this issue with reading RGB images or getting errors please look for me. Went through the same and found a fix for ti
Hi , how did you resolve this issue
I went through the following:
The next change will be on the testGenerator fn
#img = trans.resize(img,target_size)
, this line always resixe the input to (x,Y,1), a one channel shape. So avoid it when your input is 3-channeltestGene = testGenerator(test_path, flag_multi_class=True, target_size=target_size, as_gray=False)
I will suggest to save the results as tif file. Modifications to saveResults fn to be madeas follows:
io.imsave(os.path.join(save_path,"%d_predict.tif"%i),img_as_float(img))
I have two questions: If I work with RGB trainning images and I use binary masks. Do I have to put flag_multi_class=True? The other one, is if I trainned with the target size reescalled, and you mentioned to comment #img = trans.resize(img,target_size), how does the generator knows how to resize the test images? Thanks, O.
model.py:
①def unet(pretrained_weights = None,input_size = (528, 960, 3)):
②
conv9 = Conv2D(9, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9)
conv10 = Conv2D(3, 1, activation = 'sigmoid')(conv9)
data.py: ①"grayscale"→"rgb" ②#img = np.reshape(img,img.shape+(1,)) if (not flag_multi_class) else img ③#num = img[k][j] ④if img[k][j]< (threshold/255.0) → if img[k][j][0] < (threshold/255.0) and img[k][j][1] < (threshold/255.0) and img[k][j][2] < (threshold/255.0):
result:
Hi, is it possible to work with 4- or even 6-Channel-Images rather than with 3-Channel-RGB?
@deaspo I made above changes as i m using rgb training images and grayscale mask still i m getting following error. Can you plz help: ValueError: Error when checking target: expected conv2d_11 to have shape (16, 16, 1) but got array with shape (256, 256, 1)
target
Is it possible to convert the grayscale to "rgb"? The target has to be the same as the one used in training...
I have two questions: If I work with RGB trainning images and I use binary masks. Do I have to put flag_multi_class=True? The other one, is if I trainned with the target size reescalled, and you mentioned to comment #img = trans.resize(img,target_size), how does the generator knows how to resize the test images? Thanks, O.
My comment was if you want to resize your 3 channel images, don't use the numpy resize function. There are other ways to resize/reshape a 3 channel image. See here at Stack
I have two questions: If I work with RGB trainning images and I use binary masks. Do I have to put flag_multi_class=True? The other one, is if I trainned with the target size reescalled, and you mentioned to comment #img = trans.resize(img,target_size), how does the generator knows how to resize the test images? Thanks, O.
My comment was if you want to resize your 3 channel images, don't use the numpy resize function. There are other ways to resize/reshape a 3 channel image. See here at Stack
For example, I had grayscale images (or can convert to grayscale), resized them and applied stack to 3 channels again. See below for an example
img = np.resize(img,target_size)
img = np.stack((img,img,img), axis=2)
For RGB images, check the StackOverFlow
target
Is it possible to convert the grayscale to "rgb"? The target has to be the same as the one used in training... got it!!! So what changes need to be made in the code? Thanks
target
Is it possible to convert the grayscale to "rgb"? The target has to be the same as the one used in training... got it!!! So what changes need to be made in the code? Thanks
The following code you pass the input path to images you want to convert to RGB and the save path for the converted files. target size is the dimensions for the converted files and pass as gray to False. See below for example
def grayToRGBConvert(input_path, save_path, target_size = (256,256), as_gray = True):
for entry in os.listdir(input_path):
if os.path.isfile(os.path.join(input_path, entry)):
if entry.lower().endswith(('.png', '.jpg', '.jpeg')):
img = io.imread(os.path.join(input_path,entry),as_gray = as_gray)
img = np.resize(img,target_size)
img = np.stack((img,img,img), axis=2)
io.imsave(os.path.join(save_path, entry), img)
And use as follows:
target_shape = (256,256)
as_gray = False
grayToRGBConvert(test_input_path_image,test_save_path_image,target_size=target_shape, as_gray=as_gray)
The line that does actual conversion is:
img = np.stack((img,img,img), axis=2)
There are other ways, check StackOverFlow, but I use this.
Probably Is I should upload the updated data.py file with all the changes for RGB model. To do that soon
thanks for helping long way.
On Sat, Apr 11, 2020 at 1:11 AM Polycarp Okock notifications@github.com wrote:
Probably Is I should the updated data.py file with all the changes. To do that soon
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zhixuhao/unet/issues/59#issuecomment-612187239, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANAEAQACR5TW33WZQQKE4ZTRL5Y7ZANCNFSM4FNL5TIA .
Probably Is I should upload the updated data.py file with all the changes for RGB model. To do that soon
That would be great if you do so. Thanks for helping long way.
I went through the following:
- Assuming your data is 3-channel images, else you need to convert to 3-channel images. I had only gray images and converted first to 3-channel images
- in the fn trainGenerator, when calling it, pass the parameter as image_color_mode='rgb' and also mask_color_mode='rgb' if the mask images are also 3-channels.
- Before proceeding, check with the dataPrepare notebook that the trainGenerator actually generates correct augmented images by setting the path for save_to_dir. By correct I mean also 3-channels as the input used.
- If everything is okay, then the input_size to the model pass as model = unet(input_size = (X,Y,3))
The next change will be on the testGenerator fn
- Comment this line 89 -->
#img = trans.resize(img,target_size)
, this line always resixe the input to (x,Y,1), a one channel shape. So avoid it when your input is 3-channel- When calling testGenerator fn, pass the following parameters as follows: i. flag_multi_class=True ii. as_gray=False iii. Something like
testGene = testGenerator(test_path, flag_multi_class=True, target_size=target_size, as_gray=False)
- Leave the other part of the code as they are. Note target_size has to be the same as the one used in trainGenerator for the model during training.
I will suggest to save the results as tif file. Modifications to saveResults fn to be madeas follows:
io.imsave(os.path.join(save_path,"%d_predict.tif"%i),img_as_float(img))
thank you for your solution. But I follow your way to change the code that does not work. And there is a mistake that the data dimensions Is not match
I went through the following:
- Assuming your data is 3-channel images, else you need to convert to 3-channel images. I had only gray images and converted first to 3-channel images
- in the fn trainGenerator, when calling it, pass the parameter as image_color_mode='rgb' and also mask_color_mode='rgb' if the mask images are also 3-channels.
- Before proceeding, check with the dataPrepare notebook that the trainGenerator actually generates correct augmented images by setting the path for save_to_dir. By correct I mean also 3-channels as the input used.
- If everything is okay, then the input_size to the model pass as model = unet(input_size = (X,Y,3))
The next change will be on the testGenerator fn
- Comment this line 89 -->
#img = trans.resize(img,target_size)
, this line always resixe the input to (x,Y,1), a one channel shape. So avoid it when your input is 3-channel- When calling testGenerator fn, pass the following parameters as follows: i. flag_multi_class=True ii. as_gray=False iii. Something like
testGene = testGenerator(test_path, flag_multi_class=True, target_size=target_size, as_gray=False)
- Leave the other part of the code as they are. Note target_size has to be the same as the one used in trainGenerator for the model during training.
I will suggest to save the results as tif file. Modifications to saveResults fn to be madeas follows:
io.imsave(os.path.join(save_path,"%d_predict.tif"%i),img_as_float(img))
Hi,I followed all these steps, training RGB images with binary masks. But when I do the test, it gives the following error. Could you please help me to check it? Thanks
InvalidArgumentError Traceback (most recent call last)
Hi! Is it possible to use RGB images (.jpg) to train the u-net? If possible, what part of the code do I need to modify? Thanks!