Search code examples
pythonkerasimage-segmentationloss-functionpre-trained-model

TypeError while compiling Keras model with custom loss function


I have trained a model with custom loss function BinaryCrossEntropy, with Jaccard, using segmentation models library, when I tried to load and compile the model in order to start prediction, I have got this Error: model = compile(optimizer='adam', loss=bce_jaccard_loss, metrics=['iou_score']) TypeError: compile() missing required argument 'source' (pos 1)

How can I solve that please?

import keras
import segmentation_models as sm
from segmentation_models.losses import bce_jaccard_loss
from segmentation_models.metrics import iou_score

model = keras.models.load_model("ResNet_34_Aug.h5", compile = False)
model = compile(optimizer='adam', loss=bce_jaccard_loss, metrics=['iou_score'])

Solution

  • The whole problem was on the last line of the code, the missing required argument 'source' (pos 1) is the model itself, so I have fixed that to:

    model.compile(optimizer='adam', loss=bce_jaccard_loss, metrics=['iou_score'])