# Multiple output size in neural network

In the paper "A NOVEL FOCAL TVERSKY LOSS FUNCTION WITH IMPROVED ATTENTIONU-NETFOR LESION SEGMENTATION" the author use deep supervision by outputing multiple outputmask which have different scale.

I do not understand how it can work with regards to the loss function. y_pred and y_true doesnt share the same dimension exept for the final output.

model = Model(inputs=[img_input], outputs=[out6, out7, out8, out9])


the input seems to only be the one with real resolution

I checked the code (https://github.com/nabsabraham/focal-tversky-unet/blob/master/newmodels.py) and I haven't see anything special that would make it works. The loss function doesn't explicitly handle it neither.

As you can see in lines 286-296 in newmodels.py the model can use two different loss functions for the four different outputs.

loss = {'pred1':lossfxn,
'pred2':lossfxn,
'pred3':lossfxn,
'final': losses.tversky_loss}

loss_weights = {'pred1':1,
'pred2':1,
'pred3':1,
'final':1}
model.compile(optimizer=opt, loss=loss, loss_weights=loss_weights,
metrics=[losses.dsc])


The first three outputs of the model, out6, out7, and out8 uses the loss function, lossfxn, which is given as the third argument to the attn_reg function. In isic_train.py, this happens to be the Focal Tversky Loss. For the final output of the UNet (out9) the Focal Tversky Loss is always used. The total loss for the model is then the weighted sum of the different losses for the four model outputs, which is simply equal to the sum given that all weights are set to 1 in loss_weights.

• I have see this but I dont understand how the loss is computed since pred 1 2 & 3 doesnt have the same output dimension as the input. Jul 28, 2020 at 15:07
• The loss is simply computed for all four outputs seperately, resulting in four loss values. These four losses are then summed to get the total loss of the model. Jul 28, 2020 at 16:10
• Yes but how. The input image (y_true) doesn’t have the same dimension as the image pred 1 (which is downscaled) Jul 28, 2020 at 16:24
• As you can see in the image and in isic_train.py (line 75), the input consists of four multi-scale inputs. These are then used to calculate the losses for each of the four levels. Jul 28, 2020 at 16:50
• thank you very much for pointing that out, this is definitely what I was missing. In addition, didn't it is odd to use a slicing operator rather that max pooling to resample the gt image since max pooling is used to compute the downscaled input ? Jul 29, 2020 at 7:41