jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

ValueError: Cannot feed value of shape (4, 480, 480, 3) for Tensor 'y:0', which has shape '(?, ?, ?, 2)' #271

Closed Gumballing closed 5 years ago

Gumballing commented 5 years ago

Describe the bug A clear and concise description of what the bug is. The train image of mine is 4804803,the src image and mask image in same.When training there is a error: image The train command is: from tf_unet import unet,util,image_util

preparing data loading

data_provider=image_util.ImageDataProvider("./train/*.jpg")

setup & training

net=unet.Unet(layers=3,features_root=64,channels=3,n_class=2) trainer=unet.Trainer(net) path=trainer.train(data_provider,"./train-out",training_iters=32,epochs=100) To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Gumballing commented 5 years ago

What could be the cause of this problem? what should I do? Has anyone else encountered this problem?

Gumballing commented 5 years ago

Find the problem: The value of the n_class required by the network after loading the image is 3, which is 2 in my previous command. Now I used the train command net=unet.Unet(layers=3,features_root=64,channels=3,n_class=3).Training is normal. But in my mask image I only label one type of target, the other is the background, why does the n_class need to be set to 3?

obelling commented 5 years ago

I have the same problem,can you tell me how to solve this?

Gumballing commented 5 years ago

I have the same problem,can you tell me how to solve this?

You need to check the annotated images in your training data. The mask is best in grayscale.

obelling commented 5 years ago

@Gumballing While the annotated image is in grayscale(one channel),n_class is 2 ,I fear that training will has error like: Cannot feed value of shape (4, 256, 256, 1) for Tensor 'y:0', which has shape '(?, ?, ?, 2)'

obelling commented 5 years ago

I had try convert the labels to gray and successfully train the model.Thank you very mach!

Gumballing commented 5 years ago

I had try convert the labels to gray and successfully train the model.Thank you very mach!

no thank. I have some problem in testing the model.If you tested success,I will need to consult your test code.