Skip to content

Commit

Permalink
Re-add active learning
Browse files Browse the repository at this point in the history
  • Loading branch information
philippmwirth committed Sep 7, 2023
1 parent 4c44677 commit 4fa5bde
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
11 changes: 11 additions & 0 deletions lightly/active_learning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import warnings


def raise_active_learning_deprecation_warning():
warnings.warn(
"Using active learning via the lightly package is deprecated and will be removed soon. "
"Please use the Lightly Solution instead. "
"See https://docs.lightly.ai for more information and tutorials on doing active learning.",
DeprecationWarning,
stacklevel=2,
)
6 changes: 6 additions & 0 deletions lightly/active_learning/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
""" Collection of Selection Configurations """

# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved

from lightly.active_learning.config.selection_config import SelectionConfig
54 changes: 54 additions & 0 deletions lightly/active_learning/config/selection_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import warnings
from datetime import datetime

from lightly.active_learning import raise_active_learning_deprecation_warning
from lightly.openapi_generated.swagger_client.models.sampling_method import (
SamplingMethod,
)


class SelectionConfig:
"""Configuration class for a selection.
Attributes:
method:
The method to use for selection, one of CORESET, RANDOM, CORAL, ACTIVE_LEARNING
n_samples:
The maximum number of samples to be chosen by the selection
including the samples in the preselected tag. One of the stopping
conditions.
min_distance:
The minimum distance of samples in the chosen set, one of the
stopping conditions.
name:
The name of this selection, defaults to a name consisting of all
other attributes and the datetime. A new tag will be created in the
web-app under this name.
Examples:
>>> # select 100 images with CORESET selection
>>> config = SelectionConfig(method=SamplingMethod.CORESET, n_samples=100)
>>>
>>> # give your selection a name
>>> config = SelectionConfig(method=SamplingMethod.CORESET, n_samples=100, name='my-selection')
>>>
>>> # use minimum distance between samples as stopping criterion
>>> config = SelectionConfig(method=SamplingMethod.CORESET, n_samples=-1, min_distance=0.1)
"""

def __init__(
self,
method: SamplingMethod = SamplingMethod.CORESET,
n_samples: int = 32,
min_distance: float = -1,
name: str = None,
):
raise_active_learning_deprecation_warning()
self.method = method
self.n_samples = n_samples
self.min_distance = min_distance
if name is None:
date_time = datetime.now().strftime("%m_%d_%Y__%H_%M_%S")
name = f"{self.method}_{self.n_samples}_{self.min_distance}_{date_time}"
self.name = name
19 changes: 10 additions & 9 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ exclude = (?x)(
lightly/embedding/callbacks.py |
lightly/embedding/embedding.py |
lightly/core.py |
lightly/active_learning/config/selection_config.py |
lightly/api/api_workflow_compute_worker.py |
lightly/api/api_workflow_predictions.py |
lightly/api/download.py |
Expand Down Expand Up @@ -123,13 +122,6 @@ exclude = (?x)(
lightly/models/zoo.py |
lightly/models/utils.py |
lightly/models/resnet.py |
# Let's not type deprecated models:
lightly/models/simclr.py |
lightly/models/moco.py |
lightly/models/barlowtwins.py |
lightly/models/nnclr.py |
lightly/models/simsiam.py |
lightly/models/byol.py |
tests/cli/test_cli_version.py |
tests/cli/test_cli_magic.py |
tests/cli/test_cli_crop.py |
Expand Down Expand Up @@ -208,7 +200,16 @@ exclude = (?x)(
tests/api_workflow/test_api_workflow_upload_embeddings.py |
tests/api_workflow/test_api_workflow_collaboration.py |
tests/api_workflow/test_api_workflow_predictions.py |
tests/api_workflow/test_api_workflow.py )
tests/api_workflow/test_api_workflow.py |
# Let's not type check deprecated active learning:
lightly/active_learning |
# Let's not type deprecated models:
lightly/models/simclr.py |
lightly/models/moco.py |
lightly/models/barlowtwins.py |
lightly/models/nnclr.py |
lightly/models/simsiam.py |
lightly/models/byol.py )


[mypy-lightly.openapi_generated.*]
Expand Down

0 comments on commit 4fa5bde

Please sign in to comment.