I use Colab for coding and get this error:
AttributeError: module 'keras.api.backend' has no attribute 'clip'.
I have tried to upgrade TensorFlow and Keras, but I still get the same error.I get this error when fit the model at first epoch.
how could I fix it?
import segmentation_models as sm
model_vgg16=sm.Unet(backbone_name=backbone,input_shape=(256,256,3),classes=4,activation="softmax",encoder_weights="imagenet",decoder_use_batchnorm=True,encoder_freeze=False )
model_vgg16.summary()
"""# loss and metrics"""
loss="categorical_crossentropy"
dice_loss=sm.losses.DiceLoss()
focal_loss=sm.losses.CategoricalFocalLoss()
focal_dice_loss=sm.losses.categorical_focal_dice_loss
metric=[sm.metrics.IOUScore(threshold=0.5)]
"""# compile"""
lr=0.001
model_vgg16.compile(optimizer=keras.optimizers.Adam(learning_rate=lr),
loss=[focal_dice_loss],
metrics=[metric])
history = model_vgg16.fit(preprocessed_x_train, ytrain_categorical, epochs=20,validation_data=(preprocessed_x_val,y_val_categorical),batch_size=32)
**error**
Epoch 1/20
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-76-887dcd97e6be> in <cell line: 1>()
----> 1 history = model_vgg16.fit(preprocessed_x_train, ytrain_categorical, epochs=20,
2 validation_data=(preprocessed_x_val,y_val_categorical),
3 batch_size=32)
3 frames
/usr/local/lib/python3.10/dist-packages/segmentation_models/base/functional.py in categorical_focal_loss(gt, pr, gamma, alpha, class_indexes, **kwargs)
276
277 # clip to prevent NaN's and Inf's
--> 278 pr = backend.clip(pr, backend.epsilon(), 1.0 - backend.epsilon())
279
280 # Calculate focal loss
AttributeError: module 'keras.api.backend' has no attribute 'clip'
You need to sign in to view this answers