diff --git a/lightly/active_learning/__init__.py b/lightly/active_learning/__init__.py deleted file mode 100644 index 124841cb2..000000000 --- a/lightly/active_learning/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -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, - ) diff --git a/lightly/active_learning/config/__init__.py b/lightly/active_learning/config/__init__.py deleted file mode 100644 index 914442723..000000000 --- a/lightly/active_learning/config/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" Collection of Selection Configurations """ - -# Copyright (c) 2020. Lightly AG and its affiliates. -# All Rights Reserved - -from lightly.active_learning.config.selection_config import SelectionConfig diff --git a/lightly/active_learning/config/selection_config.py b/lightly/active_learning/config/selection_config.py deleted file mode 100644 index 6293b0335..000000000 --- a/lightly/active_learning/config/selection_config.py +++ /dev/null @@ -1,54 +0,0 @@ -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 diff --git a/lightly/api/__init__.py b/lightly/api/__init__.py index a5387bf9c..bc365b5c8 100644 --- a/lightly/api/__init__.py +++ b/lightly/api/__init__.py @@ -2,14 +2,17 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved -from lightly.api import patch as _patch -from lightly.api.api_workflow_artifacts import ArtifactNotExist -from lightly.api.api_workflow_client import ApiWorkflowClient -from lightly.openapi_generated.swagger_client.api_client import ( - Configuration as _Configuration, -) +from typing import TYPE_CHECKING -# Make ApiWorkflowClient and swagger classes picklable. -_patch.make_swagger_configuration_picklable( - configuration_cls=_Configuration, -) +if not TYPE_CHECKING: + from lightly.api import patch as _patch + from lightly.api.api_workflow_artifacts import ArtifactNotExist + from lightly.api.api_workflow_client import ApiWorkflowClient + from lightly.openapi_generated.swagger_client.api_client import ( + Configuration as _Configuration, + ) + + # Make ApiWorkflowClient and swagger classes picklable. + _patch.make_swagger_configuration_picklable( + configuration_cls=_Configuration, + ) diff --git a/lightly/cli/__init__.py b/lightly/cli/__init__.py index cef81ae06..efa1d30a2 100644 --- a/lightly/cli/__init__.py +++ b/lightly/cli/__init__.py @@ -5,9 +5,11 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.cli.crop_cli import crop_cli -from lightly.cli.download_cli import download_cli -from lightly.cli.embed_cli import embed_cli -from lightly.cli.lightly_cli import lightly_cli -from lightly.cli.train_cli import train_cli +if not TYPE_CHECKING: + from lightly.cli.crop_cli import crop_cli + from lightly.cli.download_cli import download_cli + from lightly.cli.embed_cli import embed_cli + from lightly.cli.lightly_cli import lightly_cli + from lightly.cli.train_cli import train_cli diff --git a/lightly/data/__init__.py b/lightly/data/__init__.py index 285cd7d8b..f222eabea 100644 --- a/lightly/data/__init__.py +++ b/lightly/data/__init__.py @@ -2,25 +2,27 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.data._video import ( - EmptyVideoError, - NonIncreasingTimestampError, - UnseekableTimestampError, - VideoError, -) -from lightly.data.collate import ( - BaseCollateFunction, - DINOCollateFunction, - ImageCollateFunction, - MAECollateFunction, - MoCoCollateFunction, - MSNCollateFunction, - MultiCropCollateFunction, - PIRLCollateFunction, - SimCLRCollateFunction, - SwaVCollateFunction, - VICRegLCollateFunction, - imagenet_normalize, -) -from lightly.data.dataset import LightlyDataset +if not TYPE_CHECKING: + from lightly.data._video import ( + EmptyVideoError, + NonIncreasingTimestampError, + UnseekableTimestampError, + VideoError, + ) + from lightly.data.collate import ( + BaseCollateFunction, + DINOCollateFunction, + ImageCollateFunction, + MAECollateFunction, + MoCoCollateFunction, + MSNCollateFunction, + MultiCropCollateFunction, + PIRLCollateFunction, + SimCLRCollateFunction, + SwaVCollateFunction, + VICRegLCollateFunction, + imagenet_normalize, + ) + from lightly.data.dataset import LightlyDataset diff --git a/lightly/embedding/__init__.py b/lightly/embedding/__init__.py index f2bb98c2d..e85df511a 100644 --- a/lightly/embedding/__init__.py +++ b/lightly/embedding/__init__.py @@ -8,5 +8,8 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved -from lightly.embedding._base import BaseEmbedding -from lightly.embedding.embedding import SelfSupervisedEmbedding +from typing import TYPE_CHECKING + +if not TYPE_CHECKING: + from lightly.embedding._base import BaseEmbedding + from lightly.embedding.embedding import SelfSupervisedEmbedding diff --git a/lightly/loss/__init__.py b/lightly/loss/__init__.py index 706045fd1..61dec51cb 100644 --- a/lightly/loss/__init__.py +++ b/lightly/loss/__init__.py @@ -2,16 +2,18 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.loss.barlow_twins_loss import BarlowTwinsLoss -from lightly.loss.dcl_loss import DCLLoss, DCLWLoss -from lightly.loss.dino_loss import DINOLoss -from lightly.loss.msn_loss import MSNLoss -from lightly.loss.negative_cosine_similarity import NegativeCosineSimilarity -from lightly.loss.ntx_ent_loss import NTXentLoss -from lightly.loss.pmsn_loss import PMSNCustomLoss, PMSNLoss -from lightly.loss.swav_loss import SwaVLoss -from lightly.loss.sym_neg_cos_sim_loss import SymNegCosineSimilarityLoss -from lightly.loss.tico_loss import TiCoLoss -from lightly.loss.vicreg_loss import VICRegLoss -from lightly.loss.vicregl_loss import VICRegLLoss +if not TYPE_CHECKING: + from lightly.loss.barlow_twins_loss import BarlowTwinsLoss + from lightly.loss.dcl_loss import DCLLoss, DCLWLoss + from lightly.loss.dino_loss import DINOLoss + from lightly.loss.msn_loss import MSNLoss + from lightly.loss.negative_cosine_similarity import NegativeCosineSimilarity + from lightly.loss.ntx_ent_loss import NTXentLoss + from lightly.loss.pmsn_loss import PMSNCustomLoss, PMSNLoss + from lightly.loss.swav_loss import SwaVLoss + from lightly.loss.sym_neg_cos_sim_loss import SymNegCosineSimilarityLoss + from lightly.loss.tico_loss import TiCoLoss + from lightly.loss.vicreg_loss import VICRegLoss + from lightly.loss.vicregl_loss import VICRegLLoss diff --git a/lightly/loss/regularizer/__init__.py b/lightly/loss/regularizer/__init__.py index 3ed727248..287499f6b 100644 --- a/lightly/loss/regularizer/__init__.py +++ b/lightly/loss/regularizer/__init__.py @@ -3,5 +3,7 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.loss.regularizer.co2 import CO2Regularizer +if not TYPE_CHECKING: + from lightly.loss.regularizer.co2 import CO2Regularizer diff --git a/lightly/models/__init__.py b/lightly/models/__init__.py index ed2f4613e..ffd4cc102 100644 --- a/lightly/models/__init__.py +++ b/lightly/models/__init__.py @@ -17,13 +17,15 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.models import utils -from lightly.models.barlowtwins import BarlowTwins -from lightly.models.byol import BYOL -from lightly.models.moco import MoCo -from lightly.models.nnclr import NNCLR -from lightly.models.resnet import ResNetGenerator -from lightly.models.simclr import SimCLR -from lightly.models.simsiam import SimSiam -from lightly.models.zoo import ZOO, checkpoints +if not TYPE_CHECKING: + from lightly.models import utils + from lightly.models.barlowtwins import BarlowTwins + from lightly.models.byol import BYOL + from lightly.models.moco import MoCo + from lightly.models.nnclr import NNCLR + from lightly.models.resnet import ResNetGenerator + from lightly.models.simclr import SimCLR + from lightly.models.simsiam import SimSiam + from lightly.models.zoo import ZOO, checkpoints diff --git a/lightly/models/modules/__init__.py b/lightly/models/modules/__init__.py index 3d8fe3d7c..2d875075d 100644 --- a/lightly/models/modules/__init__.py +++ b/lightly/models/modules/__init__.py @@ -7,31 +7,33 @@ # Copyright (c) 2021. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly import _torchvision_vit_available -from lightly.models.modules.heads import ( - BarlowTwinsProjectionHead, - BYOLPredictionHead, - BYOLProjectionHead, - DINOProjectionHead, - MoCoProjectionHead, - NNCLRPredictionHead, - NNCLRProjectionHead, - SimCLRProjectionHead, - SimSiamPredictionHead, - SimSiamProjectionHead, - SMoGPredictionHead, - SMoGProjectionHead, - SMoGPrototypes, - SwaVProjectionHead, - SwaVPrototypes, -) -from lightly.models.modules.nn_memory_bank import NNMemoryBankModule - -if _torchvision_vit_available: - # Requires torchvision >=0.12 - from lightly.models.modules.masked_autoencoder import ( - MAEBackbone, - MAEDecoder, - MAEEncoder, +if not TYPE_CHECKING: + from lightly import _torchvision_vit_available + from lightly.models.modules.heads import ( + BarlowTwinsProjectionHead, + BYOLPredictionHead, + BYOLProjectionHead, + DINOProjectionHead, + MoCoProjectionHead, + NNCLRPredictionHead, + NNCLRProjectionHead, + SimCLRProjectionHead, + SimSiamPredictionHead, + SimSiamProjectionHead, + SMoGPredictionHead, + SMoGProjectionHead, + SMoGPrototypes, + SwaVProjectionHead, + SwaVPrototypes, ) + from lightly.models.modules.nn_memory_bank import NNMemoryBankModule + + if _torchvision_vit_available: + # Requires torchvision >=0.12 + from lightly.models.modules.masked_autoencoder import ( + MAEBackbone, + MAEDecoder, + MAEEncoder, + ) diff --git a/lightly/transforms/__init__.py b/lightly/transforms/__init__.py index 33c70bdad..00df6c620 100644 --- a/lightly/transforms/__init__.py +++ b/lightly/transforms/__init__.py @@ -7,29 +7,37 @@ # Copyright (c) 2020. Lightly AG and its affiliates. # All Rights Reserved +from typing import TYPE_CHECKING -from lightly.transforms.byol_transform import ( - BYOLTransform, - BYOLView1Transform, - BYOLView2Transform, -) -from lightly.transforms.dino_transform import DINOTransform, DINOViewTransform -from lightly.transforms.fast_siam_transform import FastSiamTransform -from lightly.transforms.gaussian_blur import GaussianBlur -from lightly.transforms.jigsaw import Jigsaw -from lightly.transforms.mae_transform import MAETransform -from lightly.transforms.moco_transform import MoCoV1Transform, MoCoV2Transform -from lightly.transforms.msn_transform import MSNTransform, MSNViewTransform -from lightly.transforms.pirl_transform import PIRLTransform -from lightly.transforms.rotation import ( - RandomRotate, - RandomRotateDegrees, - random_rotation_transform, -) -from lightly.transforms.simclr_transform import SimCLRTransform, SimCLRViewTransform -from lightly.transforms.simsiam_transform import SimSiamTransform, SimSiamViewTransform -from lightly.transforms.smog_transform import SMoGTransform, SmoGViewTransform -from lightly.transforms.solarize import RandomSolarization -from lightly.transforms.swav_transform import SwaVTransform, SwaVViewTransform -from lightly.transforms.vicreg_transform import VICRegTransform, VICRegViewTransform -from lightly.transforms.vicregl_transform import VICRegLTransform, VICRegLViewTransform +if not TYPE_CHECKING: + from lightly.transforms.byol_transform import ( + BYOLTransform, + BYOLView1Transform, + BYOLView2Transform, + ) + from lightly.transforms.dino_transform import DINOTransform, DINOViewTransform + from lightly.transforms.fast_siam_transform import FastSiamTransform + from lightly.transforms.gaussian_blur import GaussianBlur + from lightly.transforms.jigsaw import Jigsaw + from lightly.transforms.mae_transform import MAETransform + from lightly.transforms.moco_transform import MoCoV1Transform, MoCoV2Transform + from lightly.transforms.msn_transform import MSNTransform, MSNViewTransform + from lightly.transforms.pirl_transform import PIRLTransform + from lightly.transforms.rotation import ( + RandomRotate, + RandomRotateDegrees, + random_rotation_transform, + ) + from lightly.transforms.simclr_transform import SimCLRTransform, SimCLRViewTransform + from lightly.transforms.simsiam_transform import ( + SimSiamTransform, + SimSiamViewTransform, + ) + from lightly.transforms.smog_transform import SMoGTransform, SmoGViewTransform + from lightly.transforms.solarize import RandomSolarization + from lightly.transforms.swav_transform import SwaVTransform, SwaVViewTransform + from lightly.transforms.vicreg_transform import VICRegTransform, VICRegViewTransform + from lightly.transforms.vicregl_transform import ( + VICRegLTransform, + VICRegLViewTransform, + ) diff --git a/lightly/utils/benchmarking/__init__.py b/lightly/utils/benchmarking/__init__.py index fc08bfa5d..dd83e4df5 100644 --- a/lightly/utils/benchmarking/__init__.py +++ b/lightly/utils/benchmarking/__init__.py @@ -1,6 +1,11 @@ -from lightly.utils.benchmarking.benchmark_module import BenchmarkModule -from lightly.utils.benchmarking.knn import knn_predict -from lightly.utils.benchmarking.knn_classifier import KNNClassifier -from lightly.utils.benchmarking.linear_classifier import LinearClassifier -from lightly.utils.benchmarking.metric_callback import MetricCallback -from lightly.utils.benchmarking.online_linear_classifier import OnlineLinearClassifier +from typing import TYPE_CHECKING + +if not TYPE_CHECKING: + from lightly.utils.benchmarking.benchmark_module import BenchmarkModule + from lightly.utils.benchmarking.knn import knn_predict + from lightly.utils.benchmarking.knn_classifier import KNNClassifier + from lightly.utils.benchmarking.linear_classifier import LinearClassifier + from lightly.utils.benchmarking.metric_callback import MetricCallback + from lightly.utils.benchmarking.online_linear_classifier import ( + OnlineLinearClassifier, + ) diff --git a/mypy.ini b/mypy.ini index f47b45218..ba127b51f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -45,10 +45,8 @@ exclude = (?x)( lightly/cli/serve_cli.py | lightly/cli/embed_cli.py | lightly/cli/lightly_cli.py | - lightly/cli/__init__.py | lightly/cli/download_cli.py | lightly/cli/config/get_config.py | - lightly/cli/config/__init__.py | lightly/cli/train_cli.py | lightly/cli/_cli_simclr.py | lightly/cli/_helpers.py | @@ -59,20 +57,17 @@ exclude = (?x)( lightly/loss/pmsn_loss.py | lightly/loss/swav_loss.py | lightly/loss/negative_cosine_similarity.py | - lightly/loss/__init__.py | lightly/loss/hypersphere_loss.py | lightly/loss/msn_loss.py | lightly/loss/dino_loss.py | lightly/loss/sym_neg_cos_sim_loss.py | lightly/loss/vicregl_loss.py | lightly/loss/dcl_loss.py | - lightly/loss/regularizer/__init__.py | lightly/loss/regularizer/co2.py | lightly/loss/barlow_twins_loss.py | lightly/data/lightly_subset.py | lightly/data/dataset.py | lightly/data/collate.py | - lightly/data/__init__.py | lightly/data/_image.py | lightly/data/_helpers.py | lightly/data/_image_loaders.py | @@ -81,12 +76,9 @@ exclude = (?x)( lightly/data/multi_view_collate.py | lightly/embedding/_base.py | lightly/embedding/callbacks.py | - lightly/embedding/__init__.py | lightly/embedding/embedding.py | lightly/core.py | - lightly/active_learning/__init__.py | lightly/active_learning/config/selection_config.py | - lightly/active_learning/config/__init__.py | lightly/api/api_workflow_compute_worker.py | lightly/api/api_workflow_predictions.py | lightly/api/download.py | @@ -98,7 +90,6 @@ exclude = (?x)( lightly/api/patch.py | lightly/api/swagger_api_client.py | lightly/api/api_workflow_collaboration.py | - lightly/api/__init__.py | lightly/api/utils.py | lightly/api/api_workflow_datasets.py | lightly/api/api_workflow_selection.py | @@ -109,7 +100,6 @@ exclude = (?x)( lightly/api/api_workflow_upload_metadata.py | lightly/api/api_workflow_tags.py | lightly/api/api_workflow_artifacts.py | - lightly/utils/cropping/__init__.py | lightly/utils/cropping/crop_image_by_bounding_boxes.py | lightly/utils/cropping/read_yolo_label_file.py | lightly/utils/reordering.py | @@ -119,25 +109,23 @@ exclude = (?x)( lightly/utils/benchmarking/knn.py | lightly/utils/benchmarking/linear_classifier.py | lightly/utils/benchmarking/topk.py | - lightly/utils/benchmarking/__init__.py | lightly/utils/benchmarking/metric_callback.py | lightly/utils/benchmarking/benchmark_module.py | lightly/utils/benchmarking/knn_classifier.py | lightly/utils/benchmarking/online_linear_classifier.py | lightly/utils/embeddings_2d.py | - lightly/models/simclr.py | lightly/models/_momentum.py | lightly/models/batchnorm.py | - lightly/models/moco.py | lightly/models/modules/heads.py | lightly/models/modules/masked_autoencoder.py | - lightly/models/modules/__init__.py | lightly/models/modules/nn_memory_bank.py | lightly/models/modules/ijepa.py | lightly/models/zoo.py | - lightly/models/__init__.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 | @@ -193,10 +181,8 @@ exclude = (?x)( tests/utils/benchmarking/test_knn.py | tests/utils/benchmarking/test_linear_classifier.py | tests/utils/benchmarking/test_metric_callback.py | - tests/utils/benchmarking/__init__.py | tests/utils/test_dist.py | tests/utils/test_version_compare.py | - tests/utils/__init__.py | tests/utils/test_io.py | tests/models/test_ModelsSimSiam.py | tests/models/modules/test_masked_autoencoder.py | @@ -212,7 +198,6 @@ exclude = (?x)( tests/api_workflow/mocked_api_workflow_client.py | tests/api_workflow/test_api_workflow_compute_worker.py | tests/api_workflow/test_api_workflow_artifacts.py | - tests/api_workflow/__init__.py | tests/api_workflow/test_api_workflow_download_dataset.py | tests/api_workflow/utils.py | tests/api_workflow/test_api_workflow_client.py |