-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
philippmwirth
committed
Sep 7, 2023
1 parent
4c44677
commit 4fa5bde
Showing
4 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters