segmentation_models icon indicating copy to clipboard operation
segmentation_models copied to clipboard

Error to train PSPNet

Open luxevar opened this issue 5 years ago • 3 comments

Hi,

I tried to modify de example for Unet multiclass in this post, replacing the Unet model for PSPNet model.

the following error is obtained when starting the model training in Colab:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-11-5600f6efe627> in <module>()
      5     callbacks=callbacks,
      6     validation_data=valid_dataloader,
----> 7     validation_steps=len(valid_dataloader)
      8     #initial_epoch      = 41
      9 )

8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     58     ctx.ensure_initialized()
     59     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60                                         inputs, attrs, num_outputs)
     61   except core._NotOkStatusException as e:
     62     if name is not None:

InvalidArgumentError:  All dimensions except 3 must match. Input 1 has shape [6 48 48 512] and doesn't match input 0 with shape [6 32 32 320].
	 [[node gradient_tape/functional_1/psp_concat/ConcatOffset (defined at <ipython-input-11-5600f6efe627>:7) ]] [Op:__inference_train_function_30002]

Function call stack:
train_function

Any idea to fix it?

luxevar avatar Sep 27 '20 19:09 luxevar

So are the images you're passing through of the same shape that the initial input expects? Also note that these architectures have different dimensionality requirements because of the downsampling that occurs. For example, PSPNet needs both the Height and Width to be evenly divisible by 6:

input_shape: shape of input data/image ``(H, W, C)``.
            ``H`` and ``W`` should be divisible by ``6 * downsample_factor`` and **NOT** ``None``!

Where as U-Net requires them to be evenly divisible by 32:

 input_shape: shape of input data/image ``(H, W, C)``, in general
            case you do not need to set ``H`` and ``W`` shapes, just pass ``(None, None, C)`` to make your model be
            able to process images af any size, but ``H`` and ``W`` of input images should be divisible by factor ``32``.

JordanMakesMaps avatar Sep 30 '20 13:09 JordanMakesMaps

@JordanMakesMaps I have images of size 768x768 which is divisible by 6 and I also set the downsampler to 4,8 or 16. I still get the same error. Can you tell me where I am making a mistake?

maheeeetaaa avatar Jul 15 '21 18:07 maheeeetaaa

It seems that the input shape has to be divided by 48, for example, (240,240,3) is ok, but (224,224,3) will have errors. Good luck. By the way, when I use PSPNet, the model does not converge, does anyone meet this problem?

jizhang02 avatar Jul 16 '21 12:07 jizhang02