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

The program generates some error messages when the images are of different sizes #1

Open
wenouyang opened this issue Dec 29, 2016 · 4 comments

Comments

@wenouyang
Copy link

Hi

Thank you for sharing the code. I have been trying to apply your code a data set, which has image size of 128*128. However, running the code gives the following error message,

ValueError: Cannot feed value of shape (32, 1, 128, 128) for Tensor 'activation_26_target:0', which has shape '(?, ?, ?)' Would you like to share any thought on the possible reason? Is that because the current implementation can only accept images with 256. If the image is of other sizes, we have to change the architecture. Thanks.

The following is the whole traceback

File "/development/tfw/lib/python3.4/site-packages/Keras-1.0.3-py3.4.egg/keras/models.py", line 409, in fit
    sample_weight=sample_weight)
  File "/development/tfw/lib/python3.4/site-packages/Keras-1.0.3-py3.4.egg/keras/engine/training.py", line 1052, in fit
    callback_metrics=callback_metrics)
  File "/development/tfw/lib/python3.4/site-packages/Keras-1.0.3-py3.4.egg/keras/engine/training.py", line 790, in _fit_loop
    outs = f(ins_batch)
  File "/development/tfw/lib/python3.4/site-packages/Keras-1.0.3-py3.4.egg/keras/backend/tensorflow_backend.py", line 659, in __call__
    updated = session.run(self.outputs + self.updates, feed_dict=feed_dict)
  File "/development/tfw/lib/python3.4/site-packages/tensorflow/python/client/session.py", line 340, in run
    run_metadata_ptr)
  File "/development/tfw/lib/python3.4/site-packages/tensorflow/python/client/session.py", line 553, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (32, 1, 128, 128) for Tensor 'activation_26_target:0', which has shape '(?, ?, ?)'
@eclique
Copy link
Member

eclique commented Dec 29, 2016

Hi @wenouyang.

Yes, current implementation requires model to be rebuild with different input_shape. Try changing img_w, img_h in build_model.py. I will look into support of different input shapes later.

@wenouyang
Copy link
Author

Hi @eclique,

Thanks for the reply. I got back to read your code again. The mask image, used in your case, is of shape (3, img_h*img_w, 2). I was trying to apply your model to the kaggle ultrasound case, in which the mask image is of shape (number_of_images, 1, img_h,img_w). Each pixel value can be 0 or 1 to present the labelling information. I think the different shape representation should be the reason to cause the error.

I am thinking of two ways to adapt your code for the kaggle case.

  1. for each mask image, which is [i,0, :,;] (i represents the i-th mask image). I can reshape it to your case.
  2. In your model building process, if my understanding is correct, the following three lines are used to ensure to handle the mask image with shape (3, img_h*img_w, n_labels), is that right? Can I modify them to make it fit to my case? Any suggestions are highly appreciated.
autoencoder.add(Reshape((n_labels, img_h * img_w)))
autoencoder.add(Permute((2, 1)))
autoencoder.add(Activation('softmax'))

@wenouyang
Copy link
Author

Hi,

Besides, the current implementation uses "softmax" for the output layer. I noticed that some other implementations, aimed to solve semantic segmentation problems, use "sigmoid" for the output layer. Would you like to share any thoughts/consideration on when or whether to use sigmoid or softmax? Thanks.

@mrgloom
Copy link

mrgloom commented Aug 1, 2017

@wenouyang sigmoid can be used when we can have not mutually exclusive classes, so each pixel can have more than one label. So as I understand we can use sigmoid + binary_crossentropy or softmax + categorical_crossentropy.

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

No branches or pull requests

3 participants