Multi-class transfer learning #394
Replies: 2 comments 6 replies
-
Thank you @bw4sz for opening a discussion on this topic. I in fact managed to successfully implement the multi-class model with my data. I used the code you provided in the link above. For me the problem is a bit different: |
Beta Was this translation helpful? Give feedback.
-
In the approach described in the docs we start with both the pre-trained backbone and pre-trained regression head. These are the parts of the model that are specific to tree detection. We use the default (untrained) classification head, so that the model can learn a different number of classes. Breaking down the code from the docs: 1. Create a new model with the appropriate number of classes for your use case m = main.deepforest(num_classes=2, label_dict={"Alive":0,"Dead":0}) 2. Get a copy of the pretrained model so that we can use parts of it in our new model deepforest_release_model = main.deepforest()
deepforest_release_model.use_release() 3. Replace the backbone of our new model with the pretrained backbone. m.model.backbone.load_state_dict(deepforest_release_model.model.backbone.state_dict()) 4. Replace the regression head of the new model with the pretrained regression head. m.model.head.regression_head.load_state_dict(deepforest_release_model.model.head.regression_head.state_dict()) Nothing is frozen in this process, so when we train the new model ( |
Beta Was this translation helpful? Give feedback.
-
Alot of users have questions about how to implement a multi-class model starting from the baseline. This is a good spot to discuss. The key first thing to understand is that the single class model needs to have the last layers removed, which correspond only to 'Tree'. From there we can retrain specific sets of classes. See the example here:
https://deepforest.readthedocs.io/en/latest/getting_started.html#multi-class-models
@aleksandraradecka1 let's discuss here, so that others may benefit. I'll try to turn this into a video tutorial if it progresses that far.
Beta Was this translation helpful? Give feedback.
All reactions