mrgloom / keras-semantic-segmentation-example

Example of semantic segmentation in Keras

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failures if image width != height

jaybo opened this issue · comments

In binary_crossentropy_example.py if I change the dimensions of the image so that the width and height are not the same, as in:

IMAGE_W = 126
IMAGE_H = 124

then I get the error:

Epoch 1/100000
Traceback (most recent call last):
File "binary_crossentropy_example.py", line 187, in <module>  train()
File "binary_crossentropy_example.py", line 182, in train callbacks=callbacks)
File "C:\Python3.6\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Python3.6\lib\site-packages\keras\engine\training.py", line 2230, in fit_generator
class_weight=class_weight)
File "C:\Python3.6\lib\site-packages\keras\engine\training.py", line 1877, in train_on_batch
class_weight=class_weight)
File "C:\Python3.6\lib\site-packages\keras\engine\training.py", line 1480, in _standardize_user_data
exception_prefix='target')
File "C:\Python3.6\lib\site-packages\keras\engine\training.py", line 123, in _standardize_input_data
str(data_shape))
ValueError: Error when checking target: expected activation_1 to have shape (9216, 1) but got array 
with shape (15624, 1)

On Windows 10
Keras 2.1.6
tensorflow 1.8.0

What example are you using binary_segmentation or multilabel_segmentation?

I'm not sure but it can be that the problem is not that width != height, but that size of image is not the same after 'upsample' part of network.
For example look at simple get_fcn_vgg16_32s
https://github.com/mrgloom/keras-semantic-segmentation-example/blob/master/binary_segmentation/models.py#L7
It have 5 MaxPooling2D, so image will be downsampled x32 times, so try to resize you image to 128x128.

This is in binary_segmentation.py.

BTW, this is such a perfect code sample for somebody just getting started, thanks! You may want to expand the readme.md slightly to point out that this is trains a variable size/oriented ellipse with random colors on random backgrounds, and what the 4 images represent.

Done!

Also this repo is extended example of ZFTurbo(Kaggle master) example:
https://github.com/ZFTurbo/ZF_UNET_224_Pretrained_Model

Also another repo(seems outdated a little) with simple starter code is:
https://github.com/jocicmarko/ultrasound-nerve-segmentation

BTW: you can check image with input size 256x128 to see if width != height is not a really issue.