fuzailpalnak / building-footprint-segmentation

Building footprint segmentation from satellite and aerial imagery
https://fuzailpalnak-buildingextraction-appbuilding-extraction-s-ov1rp9.streamlitapp.com/
Apache License 2.0
128 stars 32 forks source link

Transfer Learning #48

Closed gmommi closed 1 year ago

gmommi commented 1 year ago

Hi! I'm using the weights of the model you trained on Inria to retrain a model with other aereial images. Which layers of the RefineNet should I retrain? Thank you!

fuzailpalnak commented 1 year ago

I would suggest to train the refine net modules while keeping the backbone weights fixed

gmommi commented 1 year ago

Thank you! I don't get why if I set these parameteres like following in refinenet.py:

fuzailpalnak commented 1 year ago

I am not sure how are you loading the weights, this is how I did and its gives same weights each time model = segmentation.load_model(name="ReFineNet", transfer_weights=r"Downloads\refine\refine.pth", pre_trained_image_net = False, top_layers_trainable = False)

The pre_trained_image_net, top_layers_trainable are relevant when training from scratch, as far as just training the refine module with a pre-trained weights is concern, for that there is no direct implementation in the library, what you will have to do is after you load the model using the library function, set the params that you don't want to train to false, here is an example.

segmentation = init_segmentation("binary")

model = segmentation.load_model(name="ReFineNet", transfer_weights=r"Downloads/refine/refine.pth", pre_trained_image_net = False, top_layers_trainable = False)

for param in model.parameters():
  print(param.data)

# This will set layers from 0 to 161 to trainable = false and will only consider layers above 161 during update 
for i, param in enumerate(model.parameters()):
    if i <= 161:
        param.requires_grad = False

......
.....