Skip to content

Retrain from deeper within the architecture (include more layers) #125

@Momut1

Description

@Momut1

Hello all, I would really appreciate some assistance on how to modify the retrain.py to retrain from deeper within the model than just the final layer. As far as I understand, as it stands, the retrain.py script scraps the final layer and retrains a new one in its place and then adds a softmax to the end with the prerequisite number of classes to fit your purpose. Now my question is - how can one go deeper than that and retrain from, say, the middle of the architecture in order to be able to recognize more features. Say I want to add some dense layers like so:

x=base_model.output
x=GlobalAveragePooling2D()(x)
x=Dense(1024,activation='relu')(x) #we add dense layers so that the model can learn more complex functions and classify for better results.
x=Dense(1024,activation='relu')(x) #dense layer 2
x=Dense(512,activation='relu')(x) #dense layer 3
preds=Dense(17,activation='softmax')(x) #final layer with softmax activation

and freeze all the top layers like so:
# Freeze pretrained weights
for layer in model.layers:
layer.trainable=False

I've managed to narrow down that the function that needs to be augmented to account for this is add_final_retrain_ops , but how exactly one goes about incorporating the changes, I have no idea. Does someone have experience with this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions