Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in doubling estimators_ if model loaded from save_dir + feature for having callback after each epoch #166

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions torchensemble/soft_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,14 @@ def fit(
test_loader=None,
save_model=True,
save_dir=None,
on_epoch_end_cb=None
):

# Instantiate base estimators and set attributes
for _ in range(self.n_estimators):
self.estimators_.append(self._make_estimator())
# dont instantiate if estimators loaded from save_dir
if len(self.estimators_) != self.n_estimators:
for _ in range(self.n_estimators):
self.estimators_.append(self._make_estimator())
self._validate_parameters(epochs, log_interval)
self.n_outputs = self._decide_n_outputs(train_loader)

Expand Down Expand Up @@ -295,6 +298,9 @@ def fit(
else:
scheduler.step()

# Call on epoch end
if on_epoch_end_cb:
on_epoch_end_cb(epoch)
if save_model and not test_loader:
io.save(self, save_dir, self.logger)

Expand Down Expand Up @@ -390,6 +396,7 @@ def fit(
test_loader=None,
save_model=True,
save_dir=None,
on_epoch_end_cb=None
):
super().fit(
train_loader=train_loader,
Expand All @@ -399,6 +406,7 @@ def fit(
test_loader=test_loader,
save_model=save_model,
save_dir=save_dir,
on_epoch_end_cb=on_epoch_end_cb,
)

@torchensemble_model_doc(
Expand Down
Loading