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

feat: added LogReg into all self-supervised learning examples #1325

Merged
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion examples/self_supervised/simCLR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse

from common import add_arguments, get_contrastive_model, get_loaders
from sklearn.linear_model import LogisticRegression

from torch.optim import Adam

Expand All @@ -26,7 +27,23 @@
callbacks = [
dl.CriterionCallback(
input_key="projection_left", target_key="projection_right", metric_key="loss"
)
),
dl.SklearnModelCallback(
feature_key="embedding_origin",
target_key="target",
train_loader="train",
valid_loaders="valid",
model_fn=LogisticRegression,
predict_key="sklearn_predict",
predict_method="predict_proba",
),
dl.OptimizerCallback(metric_key="loss"),
dl.ControlFlowCallback(
dl.AccuracyCallback(
target_key="target", input_key="sklearn_predict", topk_args=(1, 3)
),
loaders="valid",
),
]

runner = SelfSupervisedRunner()
Expand All @@ -43,4 +60,5 @@
valid_metric="loss",
minimize_valid_metric=True,
num_epochs=args.epochs,
engine=dl.DeviceEngine("cpu")
Nimrais marked this conversation as resolved.
Show resolved Hide resolved
)