Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Ensembling multiple semantic segmentation models #813

Unanswered
ruipimentelfigueiredo asked this question in Q&A
Discussion options

Hello,
I was wondering if this library provides any way of averaging / voting the output of different models. If so could anyone provide an example?
Thanks

You must be logged in to vote

Replies: 3 comments

Comment options

Do you have a binary segmentation or multiple classes?
There's a simple way to implement binary segmentation ensembling by taking mean of segmentation probabilities from all models. Although this is not exactly the same as voting, it can sometimes give even better results. Multiclass segmentation can be implemented in a similar way as well.

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

Sure thing.
For example, for binary classification you can train multiple unet models with sigmoid activation function:
model = smp.Unet(encoder_name='resnet34', encoder_depth=5, encoder_weights='imagenet', activation='sigmoid')
When you finish training each of these models you save their weights so you can load them later.

Now, to make an ensemble
You can load you models into a list:
ensemble = [load_model(model_path) for model_path in list_of_model_paths]
Then for each batch you can call each model once and aggregate the results:

for data_features in data_loader:
    ensemble_prediction = torch.zeros((BATCH_SIZE, CHANNEL_SIZE, WIDTH, HEIGHT))
    for model in ensemble:
        prediction_probabilities = model(data_features)
        ensemble_prediction += prediction_probabilities

     ensemble_prediction /= len(ensemble)
     ensemble_prediction = ensemble_prediction > 0.5 # Getting 0/1 values from probabilities with 0.5 treshold

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.