keras-team / keras-io

Keras documentation, hosted live at keras.io
Apache License 2.0
2.74k stars 2.03k forks source link

How change the backend with some-pre trained model ? Object Detection with RetinaNet #1109

Open vitorbds opened 1 year ago

vitorbds commented 1 year ago

I am trying to change my backend from ResNet50 to DeseNet121. I could change the beckend without problems doing :

backbone=tf.keras.applications.densenet.DenseNet121( include_top=False, input_shape=[None,None, 3])

c3_output, c4_output, c5_output = [
        backbone.get_layer(layer_name).output
        for layer_name in ["conv3_block12_concat", "conv4_block24_concat", "conv5_block16_concat"]
    ]

    return keras.Model(
        inputs=[backbone.inputs], outputs=[c3_output, c4_output, c5_output]
    )

In get_backbone() functions. with this config the code run OK.

My problem is when i try to use some pre-trained model. Using :

backbone=tf.keras.models.load_model('cls_model/model.h5', compile=False) I am getting the follow erro :

tensorflow.python.framework.errors_impl.InvalidArgumentError:  required broadcastable shapes
         [[node gradient_tape/RetinaNetLoss/SelectV2_2 (defined at /vitor/Retina_Net/RetinaNetModel.py:147) ]] [Op:__inference_train_function_23583]

Errors may have originated from an input operation.
Input Source operations connected to node gradient_tape/RetinaNetLoss/SelectV2_2:
 RetinaNetLoss/Equal_2 (defined at /vitor/Retina_Net/RetinaNetLosses.py:72)

Function call stack:
train_function

My input shape of my trained model is input_shape=[512,512, 3]

vitorbds commented 1 year ago

@ksalama @srihari-humbarwadi Is not possible use pre-trained model like imaginet ? The input shape should be None None,3 ?