I've written the following segmentor and I can't get the accuracy to work. In fact I'm always getting accuracy of 0.0 whatever the size of my sample.
I think the problem is at the sigmoid layer at the end of U() function where a tensor of continuous elements between 0 and 1 (conv10) is further compared to a binary tensor and therefore there's no chance of getting any equality between the two.
UPDATE: The code can be found as git here
I've resolve the issue. The problem was the numpy arrays conversion to placeholder at feed level. The new update code as git can be found at : https://github.com/JulienBelanger/TensorFlow-Image-Segmentation
Related
I'm using network outputs to instantiate MultivariateNormalTriL distribution from tensorflow_probability and GradientTape to record gradients after calculating loss.
After random number of training steps GradientTape returns NaN values for some layers of the network. All the values in the outputs of the network and the distribution look ok. They are some random numbers. Not to small, not to big. All the calculated loss values are also ok. There are no NaNs anywhere else except in the gradients from the GradienTape.
Also, everything works fine when using Normal distribution.
As I understood, GradientTape should only return NaNs when the function is not differentiable. So it turns out that MultivariateNormalTriL is not differentiable for some specific values.
Am I missing something? Do you have any idea how to solve this or at least where to look?
It seems that the problem was with the standard deviation matrix. I used tfp.bijectors.FillScaleTriL to transform the matrix and it seems to be working for now.
I am new in Keras. I want to try U-net. I used this tutorial from tensorflow: https://github.com/tensorflow/models/blob/master/samples/outreach/blogs/segmentation_blogpost/image_segmentation.ipynb.
I used the code for U-net creation with my own dataset. They have got images 256x256x3 and I made my images with same shape.
Now, I got error:
InvalidArgumentError: Incompatible shapes: [1376256] vs. [458752]
[[{{node training/Adam/gradients/loss/conv2d_23_loss/mul_grad/BroadcastGradientArgs}}] ]
It is in function model.fit(). I have got 130 training examples and batch size is 5 (I know, that those number are small...).
Please, Can anybody know, what can cause this error in function model.fit()?
Thank you for your help.
1376256 is exactly 3 x 458752. I suspect you are not correctly accounting for your channels somewhere. As this appears to be on your output layer, it may be that you're trying to predict 3 classes when there are only 1.
In future, or if this doesn't help, please provide more information including the code for your model and number of classes you're trying to predict, so people can better help.
The problem is related to :
Tensorflow self-adjoint eigen decomposition not successful, input might not be valid
Is there a workaround to the use of self_adjoint_eig call in tensorflow?
I resolved the issue. the problem was with the propagation of NaN from the second loss function that I used for my stacked model.
I have trained "SSD with Mobilenet" model from Tensorflow. And training went fine.
Now when I try to test the performance of inference graph by running object_detection_tutorial.ipynb on an image, I get following error:
ValueError: cannot reshape array of size X into shape (a,b,c)
X,a,b,c are different values for different test images.
I don't think image size is causing the issue as model must perform independent of input image size. Infact, I get this error even with an image I used for training.
Please help here.
As suggested by #Mandroid, programmatically changing the input image to 3 channel might be the way to go, but this is how I ended up solving my issue.
Note: I am not sure that removing alpha from the images might have some consequences. This is some kind of information loss however.
Replacing image = Image.open(<image_path>) with image = Image.open(<image_path>).convert('RGB') did the job for me.
Replacing a tensor t in my model by t*1 change numerical behavior significantly, and causes nans to propagate to the loss.
Before I take this to github issues, I was wondering if someone know a workaround for this "magic".
I am using version 1.0