Hi, I test a deeplearning model for image segmentation with the library Segmentation Model based on Keras (Tensorflow) framework.
import segmentation_models as sm
model = sm.Unet(
backbone_name = BACKBONE,
encoder_weights = "imagenet", # poids prédéfini après entrainement sur les images du dataset ImageNet
input_shape = (512,512,3),
activation = "sigmoid"
)
from tensorflow.keras.optimizers import Adam
optimizer = Adam(learning_rate=5e-4)
loss = sm.losses.dice_loss
metric = sm.metrics.iou_score
model.compile(
optimizer = optimizer,
loss = loss,
metrics = [metric],
)
...
**It works not so bad. So I saved it like this : **
...
model.save("RetinaNeuroneCounter.h5")
Now I would like tu resuse this model with a new data set. I'm working with GoogleColab. I follow these steps : 1-Data importation
!wget -O RetinaNeurons.zip https://mycore.core-cloud.net/index.php/s/k1vLbyRF5tTf189/download
!unzip -qq RetinaNeurons.zip
!rm -f RetinaNeurons.zip
**2-model importation **
!wget -O RetinaNeuroneCounter.h5 https://mycore.core-cloud.net/index.php/s/VnbPHdf6T8ylU1e/download
!rm -f RetinaNeuroneCounter.h5
**3-I reload my model to test on new data **
import tensorflow.keras as keras
from keras.models import load_model
model = load_model("./drive/MyDrive/RetinaNeurons/RetinaNeuroneCounter.h5")
--> Error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-9fe7242d9e02> in <module>
1 import tensorflow.keras as keras
2 from keras.models import load_model
----> 3 model = load_model("./drive/MyDrive/RetinaNeurons/RetinaNeuroneCounter.h5")
4 #model = keras.models.load_model('RetinaNeuroneCounter.h5')
5 #saved_models = 'D:\VGigot\TRAVAUX\Traitement Image CSGA\Elodie Masson - Elise Léger-Charnay\IA-DeepLearning-RetinaNeurons'
1 frames
/usr/local/lib/python3.8/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
707 obj = module_objects.get(object_name)
708 if obj is None:
--> 709 raise ValueError(
710 f'Unknown {printable_module_name}: {object_name}. Please ensure '
711 'this object is passed to the `custom_objects` argument. See '
ValueError: Unknown loss function: dice_loss. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
I don't understand, Dice_loss is one the usable loss function :
segmentation_models.losses.DiceLoss(beta=1, class_weights=None, class_indexes=None, per_image=False, smooth=1e-05)
Returns:
A callable dice_loss instance. Can be used in model.compile(...) function` or combined with other losses.
Any idea how to code to reuse a model in a new notebook ? Thanks.