MrGiovanni / UNetPlusPlus

[IEEE TMI] Official Implementation for UNet++
Other
2.26k stars 538 forks source link

Problems on Xnet #6

Open xjw00654 opened 5 years ago

xjw00654 commented 5 years ago

I have some problems on building Xnet.

in segmentation_models/xnet/blocks.py : 38 x = Concatenate(name=merge_name)([x, skip]) in merge_name="merge2-2", variables: skip is a Tensor list which we want to concatenate while x is a single Tensor. Thus generating the following error message (my input shape is (512, 512, 3)):

Traceback (most recent call last): File "/home/xjw/pycharm/helpers/pydev/pydevd.py", line 1664, in main() File "/home/xjw/pycharm/helpers/pydev/pydevd.py", line 1658, in main globals = debugger.run(setup['file'], None, None, is_module) File "/home/xjw/pycharm/helpers/pydev/pydevd.py", line 1068, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/home/xjw/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/xjw/Projects/image-segmentation-keras/train.py", line 56, in input_shape=(input_height, input_width, 3))} File "/home/xjw/Projects/image-segmentation-keras/Models/segmentation_models/xnet/model.py", line 100, in Xnet use_batchnorm=decoder_use_batchnorm) File "/home/xjw/Projects/image-segmentation-keras/Models/segmentation_models/xnet/builder.py", line 83, in build_xnet use_batchnorm=use_batchnorm)(interm[(n_upsample_blocks+1)*(i+1)+j]) File "/home/xjw/Projects/image-segmentation-keras/Models/segmentation_models/xnet/blocks.py", line 38, in layer x = Concatenate(name=merge_name)([x, skip]) # Problems on it! File "/home/xjw/anaconda3/lib/python3.5/site-packages/keras/engine/base_layer.py", line 414, in call self.assert_input_compatibility(inputs) File "/home/xjw/anaconda3/lib/python3.5/site-packages/keras/engine/base_layer.py", line 285, in assert_input_compatibility str(inputs) + '. All inputs to the layer ' ValueError: Layer merge_2-2 was called with an input that isn't a symbolic tensor. Received type: <class 'list'>. Full input: [<tf.Tensor 'decoder_stage2-2_upsample/ResizeNearestNeighbor:0' shape=(?, 256, 256, 128) dtype=float32>, [<tf.Tensor 'relu0/Relu:0' shape=(?, 256, 256, 64) dtype=float32>, <tf.Tensor 'decoder_stage2-1_relu2/Relu:0' shape=(?, 256, 256, 64) dtype=float32>]]. All inputs to the layer should be tensors.

hlaanaya commented 5 years ago

I have the same issue. The problem is, in some cases, skip is a list of tensors and x is a tensor. For a workaround (solution), you can modify the function Upsample2D_block (these lines) https://github.com/MrGiovanni/Nested-UNet/blob/6b6b686d2ee81d951af94f36d529319871356662/segmentation_models/xnet/blocks.py#L37-L38 of blocks.py inside segmentation_models/xnet/ with this portion of code (that you can find in Transpose2D_block function) https://github.com/MrGiovanni/Nested-UNet/blob/6b6b686d2ee81d951af94f36d529319871356662/segmentation_models/xnet/blocks.py#L63-L72 to ensure that skip is not None and does not contain None if it is a list of tensors. Happy coding.

shishichang commented 5 years ago

me too

JonnoFTW commented 5 years ago

To make it easier for other people, the fix is to replace: https://github.com/MrGiovanni/UNetPlusPlus/blob/06088ad7d95673776c2168ceb3f5f720faee53a0/segmentation_models/xnet/blocks.py#L37-L38

with

        if (type(skip) != list and skip is not None) or (type(skip) == list and None not in skip):
            if type(skip) is list:
                x = Concatenate(name=merge_name)([x] + skip)
            else:
                x = Concatenate(name=merge_name)([x, skip])