Ensemble PyTorch Documentation

Ensemble PyTorch is a unified ensemble framework for PyTorch to easily improve the performance and robustness of your deep learning model. It provides:

  • Easy ways to improve the performance and robustness of your deep learning model.

  • Easy-to-use APIs on training and evaluating the ensemble.

  • High training efficiency with parallelization.


  • To get started, please refer to Quick Start;

  • To learn more about ensemble methods supported, please refer to Introduction;

  • If you are confused on which ensemble method to use, our experiments and the instructions in guidance may be helpful.


from torchensemble import VotingClassifier  # voting is a classic ensemble strategy

# Load data
train_loader = DataLoader(...)
test_loader = DataLoader(...)

# Define the ensemble
ensemble = VotingClassifier(
    estimator=base_estimator,               # here is your deep learning model
    n_estimators=10,                        # number of base estimators

# Set the optimizer
    "Adam",                                 # type of parameter optimizer
    lr=learning_rate,                       # learning rate of parameter optimizer
    weight_decay=weight_decay,              # weight decay of parameter optimizer

# Set the learning rate scheduler
    "CosineAnnealingLR",                    # type of learning rate scheduler
    T_max=epochs,                           # additional arguments on the scheduler

# Train the ensemble
    epochs=epochs,                          # number of training epochs

# Evaluate the ensemble
acc = ensemble.predict(test_loader)         # testing accuracy