Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starting U-net #91

Closed
Fab1900 opened this issue Sep 2, 2017 · 33 comments
Closed

starting U-net #91

Fab1900 opened this issue Sep 2, 2017 · 33 comments
Labels

Comments

@Fab1900
Copy link

Fab1900 commented Sep 2, 2017

Hey,

I would like to use the proposed U-net for my work but I am still a beginner with Python and Tensorflow. My current problem that I cant really start the code in general because python crashes already at the start. I think the issue is that I don't set the required parameters right at the beginning, I read the documentation but it is not clear for me yet which parameters I have to define and how (for example output path).
Can someone help me please?

Kind regards,
Fabian

@jakeret
Copy link
Owner

jakeret commented Sep 2, 2017

Hmm this is rather vage... ;-) Some error message would certainly help.

Make sure you have all dependencies installed

pip install -r requirements.txt

To look at the demo notebooks you will also need jupyter and matplotlib. After this I would suggest you look at the examples in the scripts folder. Note however that the package does not ship with example data. So most will not run out of the box

@Fab1900
Copy link
Author

Fab1900 commented Sep 4, 2017

Yes, I have all dependencies installed.
The problem is that I don't really get an error message from the command, just a window pops up which says "Python does not work anymore" .

@jakeret
Copy link
Owner

jakeret commented Sep 4, 2017

This sounds like your interpreter is crashing. I doubt that this is unet specific. Can you import tensorflow without the crash?

@Fab1900
Copy link
Author

Fab1900 commented Sep 4, 2017

Yes that is no problem, also the test version TestTf_unet.py runs without errors.

@Fab1900
Copy link
Author

Fab1900 commented Sep 4, 2017

Ok, I am not sure if this is the issue but now i changed my trainingdata from the .png file format to .tiff. Anyway now I get the error: "Could not broadcast input array from shape <3600,1400,4> into shape <3600,1400>... Do you know what i have to change? Aren't you using the .tiff format aswell?

@jakeret
Copy link
Owner

jakeret commented Sep 5, 2017

Ok thats better. tf_unet uses the Pillow package to load images. In principle this should support tiff and png...
Anyway, I presume that the data has 4 channels or 4 classes. The ImageDataProvider implicitly assumes another number but you can easily change it after creating the instance:

provider = ImageDataProvider(...)
provider.n_class = 27

@Fab1900
Copy link
Author

Fab1900 commented Sep 7, 2017

But actually my data has only one channel, I am using the following code (attached) to run the Unet with my dataset which has the size (3601,1487). I am sure there must be somewhere the error.
Can you tell me do have to change? I am sry but the demo and the Scrips didn't really help me:

unet_starter_

@Fab1900
Copy link
Author

Fab1900 commented Sep 7, 2017

Now I am using this script for launching but I get an error because of "incompatible shapes"?
Can someone help me please?
unet_starter_

@jakeret
Copy link
Owner

jakeret commented Sep 8, 2017

Not 100% sure (because the relevant bit of the traceback is missing) but this might be due a known, unresolved bug in package (#6, #89): The problem could be the uneven number of pixels (1445)

Could you try to crop the input images to event pixel counts?

As a side note: The input images seem rather large. In the original paper 576*576 was used

@Fab1900
Copy link
Author

Fab1900 commented Sep 8, 2017

This is true but it is mentioned that this network can applied to images with
arbitrarily size. Yes you are right that was the issue.
My output image is not the same size as the input image, in the paper it is also shown that this is on purpose but is there a way to get the same size?

@jakeret
Copy link
Owner

jakeret commented Sep 8, 2017

Well it's a bug..

In principle you can increase the size of the input image by mirroring the borders. There are some examples on how to do this in the issues

@Fab1900
Copy link
Author

Fab1900 commented Sep 8, 2017

Thanks for your help! I was looking through the issues, and there were a couple of issues about that. The propse of mirroring appeared very often, but how can I code that in Tensor Flow?

@jakeret
Copy link
Owner

jakeret commented Sep 8, 2017

you don't have to do this with tensorflow. People usually use opencv for that

@jakeret
Copy link
Owner

jakeret commented Sep 8, 2017

see #41

@Fab1900
Copy link
Author

Fab1900 commented Sep 8, 2017

But with this method the pixels of output_image isn't 1:1 the input_image, is it?
So for example you can't say exactly pixel at (250,43) of the output_image is representing the class of pixel (250,43) of the input_image?

@Fab1900
Copy link
Author

Fab1900 commented Sep 11, 2017

???

@jakeret
Copy link
Owner

jakeret commented Sep 11, 2017

Not quite sure if I understand what you mean

@AlibekJ
Copy link

AlibekJ commented Sep 11, 2017 via email

@Fab1900
Copy link
Author

Fab1900 commented Sep 12, 2017

Thanks for your answer. I was looking through the issues, and the only one solution I found was was the proposed adding of borders to the input image. I was just wondering if then I still have an exact pixel correspondence of the input image and the prediction image. And if I make my input image larger via mirroring the borders, I have to remove and change all the crop and rehape functions in the code, is that right?

@AlibekJ
Copy link

AlibekJ commented Sep 12, 2017 via email

@Fab1900
Copy link
Author

Fab1900 commented Sep 12, 2017

I am sry but I don't understand what you mean.

@AlibekJ
Copy link

AlibekJ commented Sep 12, 2017

Ok, say you have input pictures of 1000x1000 resolution and your output pictures are 250x250.
Pixel 100,100 on your original would correspond to 25x25 on the output.
What pixel 100, 200 will correspond to?

You need to find out how output pixels relate to the original ones and just multiply the coordinates accordingly.

@Fab1900
Copy link
Author

Fab1900 commented Sep 13, 2017

Ah ok I understand, i will try this. Thanks for your help!

@Fab1900
Copy link
Author

Fab1900 commented Sep 13, 2017

Unfortunatley I have now another issue with training, I hope it is ok if I share it with you?
When I use the dice coefficient I get from Epoch_0 only black images. I had the same NaN problem as in issue #28, so I added:" exponential_map = tf.exp(tf.clip_by_value(output_map, -np.inf, 50))". But the result are black images, do you have an idea what is going on?

@jakeret
Copy link
Owner

jakeret commented Sep 13, 2017

I suspect that this happens when some of the gradients explode for whatever reason. So far I haven't found a definitve answer to that.
Unfortunately, I can only point you to my question to the end of #28 or to try to implement a new version of the pixelwise_softmax, by flatting the image, passing it thru the tensorflow softmax and then reshaping it back. Would be very interested to see if that helps

@Fab1900
Copy link
Author

Fab1900 commented Sep 14, 2017

Ok thanks I will try.
Is the code also useable for input images of different size during a training? Because I get an dimension miss match with this error:

Traceback (most recent call last):
File "C:\Users\eclipse-workspace\SimpleNet\SimpleNet\Run_Unet.py", line 45, in
epochs, restore, layers, features_root)
File "C:\Users\eclipse-workspace\SimpleNet\SimpleNet\Run_Unet.py", line 33, in launch
restore=restore)
File "c:\users\appdata\local\programs\python\python35\tf_unet\tf_unet\unet.py", line 424, in train
self.net.keep_prob: dropout})
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
run_metadata_ptr)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1124, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1321, in _do_run
options, run_metadata)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1340, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[4760672,2] labels_size=[0,2]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape_31, Reshape_32)]]
[[Node: gradients/add_7_grad/Reshape_1/_87 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_2668_gradients/add_7_grad/Reshape_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]

Unforunately I couldn't figure out what to change in the code and I don't want to zero-pad the images to the same input size.

@jakeret
Copy link
Owner

jakeret commented Sep 15, 2017

Frankly, this is something I have never tried. Probably the easiest is to reshape all the inputs to the same size

@chutongz
Copy link

I have the exact same problem.
How did you fix it?

@Fab1900
Copy link
Author

Fab1900 commented Jan 29, 2018

Which of the discussed problems do you mean in particular?

@chutongz
Copy link

I also meet the problem of invalidArgumentError, the logits and labels must have the same size.

@Fab1900
Copy link
Author

Fab1900 commented Jan 29, 2018

I resized all input images to the same dimensions.

@AlibekJ
Copy link

AlibekJ commented Jan 30, 2018 via email

@azizmrr
Copy link

azizmrr commented Dec 26, 2018

I resized all input images to the same dimensions.

hey, I have only one image and both mask and image are same size so why am I still getting "InvalidArgumentError: logits and labels must be broadcastable: logits_size=[1140224,2] labels_size=[1142400,2]" eorror? Note that these are not obviously the size of input image and mask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants