Search is not available for this dataset
repo stringlengths 2 152 ⌀ | file stringlengths 15 239 | code stringlengths 0 58.4M | file_length int64 0 58.4M | avg_line_length float64 0 1.81M | max_line_length int64 0 12.7M | extension_type stringclasses 364
values |
|---|---|---|---|---|---|---|
lightly | lightly-master/lightly/transforms/image_grid_transform.py | from typing import List, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
class ImageGridTransform:
"""Transforms an image into multiple views and grids.
Used for VICRegL.
Attributes:
transforms:
A sequence of (image_grid_transform... | 1,666 | 31.057692 | 88 | py |
lightly | lightly-master/lightly/transforms/jigsaw.py | # Copyright (c) 2021. Lightly AG and its affiliates.
# All Rights Reserved
import numpy as np
import torch
from PIL import Image
from torchvision import transforms
class Jigsaw(object):
"""Implementation of Jigsaw image augmentation, inspired from PyContrast library.
Generates n_grid**2 random crops and ret... | 2,448 | 31.653333 | 103 | py |
lightly | lightly-master/lightly/transforms/mae_transform.py | from typing import List, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.utils import IMAGENET_NORMALIZE
class MAETransform:
"""Implements the view augmentation for... | 1,826 | 26.268657 | 88 | py |
lightly | lightly-master/lightly/transforms/moco_transform.py | from typing import Optional, Tuple, Union
from lightly.transforms.simclr_transform import SimCLRTransform
from lightly.transforms.utils import IMAGENET_NORMALIZE
class MoCoV1Transform(SimCLRTransform):
"""Implements the transformations for MoCo v1.
Input to this transform:
PIL Image or Tensor.
... | 6,331 | 35.182857 | 119 | py |
lightly | lightly-master/lightly/transforms/msn_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.utils import IMAGENET_NORMALIZE
c... | 6,537 | 33.962567 | 119 | py |
lightly | lightly-master/lightly/transforms/multi_crop_transform.py | from typing import Tuple
import torchvision.transforms as T
from lightly.transforms.multi_view_transform import MultiViewTransform
class MultiCropTranform(MultiViewTransform):
"""Implements the multi-crop transformations. Used by Swav.
Input to this transform:
PIL Image or Tensor.
Output of th... | 2,408 | 30.285714 | 80 | py |
lightly | lightly-master/lightly/transforms/multi_view_transform.py | from typing import List, Union
from PIL.Image import Image
from torch import Tensor
class MultiViewTransform:
"""Transforms an image into multiple views.
Args:
transforms:
A sequence of transforms. Every transform creates a new view.
"""
def __init__(self, transforms):
... | 775 | 22.515152 | 88 | py |
lightly | lightly-master/lightly/transforms/pirl_transform.py | from typing import Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.jigsaw import Jigsaw
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_transform
from lightly.tra... | 3,654 | 30.508621 | 84 | py |
lightly | lightly-master/lightly/transforms/random_crop_and_flip_with_grid.py | from dataclasses import dataclass
from typing import Dict, List, Tuple
import torch
import torchvision.transforms as T
import torchvision.transforms.functional as F
from PIL import Image
from torch import nn
@dataclass
class Location:
# The row index of the top-left corner of the crop.
top: float
# The c... | 7,147 | 33.868293 | 119 | py |
lightly | lightly-master/lightly/transforms/rotation.py | # Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
from typing import Tuple, Union
import numpy as np
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from torchvision.transforms import functional as TF
class RandomRotate:
"""Implementation of rando... | 2,951 | 30.404255 | 106 | py |
lightly | lightly-master/lightly/transforms/simclr_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_tra... | 6,447 | 34.043478 | 119 | py |
lightly | lightly-master/lightly/transforms/simsiam_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_tra... | 6,130 | 34.439306 | 119 | py |
lightly | lightly-master/lightly/transforms/smog_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.solarize import RandomSolarization
... | 6,163 | 33.435754 | 92 | py |
lightly | lightly-master/lightly/transforms/solarize.py | # Copyright (c) 2021. Lightly AG and its affiliates.
# All Rights Reserved
import numpy as np
from PIL import ImageOps
class RandomSolarization(object):
"""Implementation of random image Solarization.
Utilizes the integrated image operation `solarize` from Pillow. Solarization
inverts all pixel values a... | 1,118 | 25.642857 | 80 | py |
lightly | lightly-master/lightly/transforms/swav_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_crop_transform import MultiCropTranform
from lightly.transforms.rotation import random_rotation_tran... | 6,338 | 33.82967 | 119 | py |
lightly | lightly-master/lightly/transforms/utils.py | IMAGENET_NORMALIZE = {"mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225]}
| 83 | 41 | 82 | py |
lightly | lightly-master/lightly/transforms/vicreg_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_tra... | 6,402 | 34.181319 | 119 | py |
lightly | lightly-master/lightly/transforms/vicregl_transform.py | from typing import Optional, Tuple, Union
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.image_grid_transform import ImageGridTransform
from lightly.transforms.random_crop_and_flip_with_grid impo... | 8,838 | 37.938326 | 88 | py |
lightly | lightly-master/lightly/utils/__init__.py | 0 | 0 | 0 | py | |
lightly | lightly-master/lightly/utils/bounding_box.py | """ Bounding Box Utils """
# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
class BoundingBox:
"""Class which unifies different bounding box formats.
Attributes:
x0:
x0 coordinate (normalized to [0, 1])
y0:
y0 coordinate (normalized to [0, 1... | 3,469 | 28.40678 | 103 | py |
lightly | lightly-master/lightly/utils/debug.py | from typing import List, Union
import torch
import torchvision
from PIL import Image
from lightly.data.collate import BaseCollateFunction, MultiViewCollateFunction
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
plt = ModuleNotFoundError(
"Matplotlib is not installed on your system. ... | 5,552 | 32.251497 | 103 | py |
lightly | lightly-master/lightly/utils/dist.py | from typing import Optional, Tuple
import torch
import torch.distributed as dist
class GatherLayer(torch.autograd.Function):
"""Gather tensors from all processes, supporting backward propagation.
This code was taken and adapted from here:
https://github.com/Spijkervet/SimCLR
"""
@staticmethod
... | 2,171 | 29.591549 | 80 | py |
lightly | lightly-master/lightly/utils/embeddings_2d.py | """ Transform embeddings to two-dimensional space for visualization. """
# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
import numpy as np
class PCA(object):
"""Handmade PCA to bypass sklearn dependency.
Attributes:
n_components:
Number of principal component... | 2,604 | 26.712766 | 83 | py |
lightly | lightly-master/lightly/utils/hipify.py | import copy
import warnings
from typing import Type
class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
def _custom_formatwarning(msg, *args, **kwargs):
# ignore... | 675 | 22.310345 | 79 | py |
lightly | lightly-master/lightly/utils/io.py | """ I/O operations to save and load embeddings. """
# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
import csv
import json
import re
from itertools import compress
from typing import Dict, List, Tuple
import numpy as np
INVALID_FILENAME_CHARACTERS = [","]
def _is_valid_filename(filename... | 11,880 | 30.938172 | 108 | py |
lightly | lightly-master/lightly/utils/lars.py | import torch
from torch.optim.optimizer import Optimizer, required
class LARS(Optimizer):
"""Extends SGD in PyTorch with LARS scaling from the paper "Large batch training of
Convolutional Networks" [0].
Implementation from PyTorch Lightning Bolts [1].
- [0]: https://arxiv.org/pdf/1708.03888.pdf
... | 5,481 | 33.477987 | 141 | py |
lightly | lightly-master/lightly/utils/reordering.py | from typing import List, Sized
def sort_items_by_keys(keys: List[any], items: List[any], sorted_keys: List[any]):
"""Sorts the items in the same order as the sorted keys.
Args:
keys:
Keys by which items can be identified.
items:
Items to sort.
sorted_keys:
... | 1,178 | 27.756098 | 82 | py |
lightly | lightly-master/lightly/utils/scheduler.py | import warnings
import numpy as np
import torch
def cosine_schedule(
step: float, max_steps: float, start_value: float, end_value: float
) -> float:
"""
Use cosine decay to gradually modify start_value to reach target end_value during iterations.
Args:
step:
Current step number.
... | 3,212 | 26.461538 | 97 | py |
lightly | lightly-master/lightly/utils/version_compare.py | """ Utility method for comparing versions of libraries """
# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
def version_compare(v0: str, v1: str):
"""Returns 1 if version of v0 is larger than v1 and -1 otherwise
Use this method to compare Python package versions and see which one i... | 885 | 25.848485 | 84 | py |
lightly | lightly-master/lightly/utils/benchmarking/__init__.py | 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 imp... | 426 | 60 | 86 | py |
lightly | lightly-master/lightly/utils/benchmarking/benchmark_module.py | # Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved
from typing import List, Optional
import torch
import torch.distributed as dist
import torch.nn as nn
import torch.nn.functional as F
from pytorch_lightning import LightningModule
from torch import Tensor
from torch.utils.data import DataLoade... | 6,475 | 38.975309 | 83 | py |
lightly | lightly-master/lightly/utils/benchmarking/knn.py | import torch
from torch import Tensor
# code for kNN prediction from here:
# https://colab.research.google.com/github/facebookresearch/moco/blob/colab-notebook/colab/moco_cifar10_demo.ipynb
def knn_predict(
feature: Tensor,
feature_bank: Tensor,
feature_labels: Tensor,
num_classes: int,
knn_k: in... | 2,538 | 31.139241 | 114 | py |
lightly | lightly-master/lightly/utils/benchmarking/knn_classifier.py | from typing import Tuple, Union
import torch
import torch.nn.functional as F
from pytorch_lightning import LightningModule
from torch import Tensor
from torch.nn import Module
from lightly.models.utils import activate_requires_grad, deactivate_requires_grad
from lightly.utils.benchmarking import knn_predict
from ligh... | 6,214 | 38.839744 | 88 | py |
lightly | lightly-master/lightly/utils/benchmarking/linear_classifier.py | from typing import Dict, Tuple
from pytorch_lightning import LightningModule
from torch import Tensor
from torch.nn import CrossEntropyLoss, Linear, Module
from torch.optim import SGD
from lightly.models.utils import activate_requires_grad, deactivate_requires_grad
from lightly.utils.benchmarking.topk import mean_top... | 5,896 | 37.292208 | 88 | py |
lightly | lightly-master/lightly/utils/benchmarking/metric_callback.py | from typing import Dict, List
from pytorch_lightning import LightningModule, Trainer
from pytorch_lightning.callbacks import Callback
from torch import Tensor
class MetricCallback(Callback):
"""Callback that collects log metrics from the LightningModule and stores them after
every epoch.
Attributes:
... | 2,432 | 35.863636 | 88 | py |
lightly | lightly-master/lightly/utils/benchmarking/online_linear_classifier.py | from typing import Dict, Tuple
from pytorch_lightning import LightningModule
from torch import Tensor
from torch.nn import CrossEntropyLoss, Linear
from lightly.utils.benchmarking.topk import mean_topk_accuracy
class OnlineLinearClassifier(LightningModule):
def __init__(
self,
feature_dim: int =... | 1,811 | 37.553191 | 85 | py |
lightly | lightly-master/lightly/utils/benchmarking/topk.py | from typing import Dict, Sequence
import torch
from torch import Tensor
def mean_topk_accuracy(
predicted_classes: Tensor, targets: Tensor, k: Sequence[int]
) -> Dict[int, Tensor]:
"""Computes the mean accuracy for the specified values of k.
The mean is calculated over the batch dimension.
Args:
... | 1,138 | 31.542857 | 87 | py |
lightly | lightly-master/lightly/utils/cropping/crop_image_by_bounding_boxes.py | import os.path
import warnings
from pathlib import Path
from typing import List
from PIL import Image
from tqdm import tqdm
from lightly.data import LightlyDataset
from lightly.utils.bounding_box import BoundingBox
def crop_dataset_by_bounding_boxes_and_save(
dataset: LightlyDataset,
output_dir: str,
bo... | 4,398 | 39.357798 | 108 | py |
lightly | lightly-master/lightly/utils/cropping/read_yolo_label_file.py | from typing import List, Tuple
from lightly.utils.bounding_box import BoundingBox
def read_yolo_label_file(
filepath: str, padding: float, separator: str = " "
) -> Tuple[List[int], List[BoundingBox]]:
"""Reads a file in the yolo file format
Args:
filepath:
The path to the yolo file,... | 1,269 | 29.97561 | 106 | py |
lightly | lightly-master/tests/REAMDE.md | # How to write tests for the API
There are three different locations to write tests for the API, each with its
own advantages and disadvantages:
1. In tests/api_workflow_client:
This is for testing the api_workflow_client directly with the ability to configure its mocked version fully.
Furthermore, you have a (partly... | 619 | 46.692308 | 108 | md |
lightly | lightly-master/tests/__init__.py | 0 | 0 | 0 | py | |
lightly | lightly-master/tests/conftest.py | # content of conftest.py
import os
from unittest import mock
import pytest
def pytest_addoption(parser):
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
def pytest_configure(config):
"""Pytest configuration hook, for docs see:
https://docs.pytest.... | 2,681 | 35.739726 | 94 | py |
lightly | lightly-master/tests/UNMOCKED_end2end_tests/README.md | This repository contains scripts to test the python package with a server.
## Testing the Server API with CLI commands and active learning
You only need an account on the server.
Once you have a token from our production server `https://app.lightly.ai`, you can run:
```bash
cd ../../../lightly # ensure you are in the... | 1,112 | 37.37931 | 118 | md |
lightly | lightly-master/tests/UNMOCKED_end2end_tests/create_custom_metadata_from_input_dir.py | import sys
from lightly.data import LightlyDataset
from lightly.utils.io import save_custom_metadata
if __name__ == "__main__":
if len(sys.argv) == 1 + 2:
input_dir, metadata_filename = (sys.argv[1 + i] for i in range(2))
else:
raise ValueError(
"ERROR in number of command line arg... | 783 | 31.666667 | 98 | py |
lightly | lightly-master/tests/UNMOCKED_end2end_tests/delete_datasets_test_unmocked_cli.py | import sys
from lightly.api import ApiWorkflowClient
if __name__ == "__main__":
if len(sys.argv) == 1 + 3:
num_datasets, token, date_time = (sys.argv[1 + i] for i in range(3))
else:
raise ValueError(
"ERROR in number of command line arguments, must be 3."
"Example: pyth... | 750 | 34.761905 | 102 | py |
lightly | lightly-master/tests/UNMOCKED_end2end_tests/run_all_unmocked_tests.sh | #!/bin/bash
set -e
# Get the parameters
export LIGHTLY_TOKEN=$1
[[ -z "$LIGHTLY_TOKEN" ]] && { echo "Error: token is empty" ; exit 1; }
echo "############################### token: ${LIGHTLY_TOKEN}"
DATE_TIME=$(date +%Y-%m-%d-%H-%M-%S)
echo "############################### Download the clothing_dataset_small"
DIR_D... | 1,045 | 31.6875 | 113 | sh |
lightly | lightly-master/tests/UNMOCKED_end2end_tests/scripts_for_reproducing_problems/test_api_latency.py | import os
import time
import numpy as np
from tqdm import tqdm
from lightly.api import ApiWorkflowClient
from lightly.openapi_generated.swagger_client import ApiClient, Configuration, QuotaApi
if __name__ == "__main__":
token = os.getenv("LIGHTLY_TOKEN")
api_client = ApiWorkflowClient(token=token).api_client... | 955 | 27.969697 | 148 | py |
lightly | lightly-master/tests/api/benchmark_video_download.py | import time
import unittest
import av
import numpy as np
from tqdm import tqdm
from lightly.api.download import (
download_all_video_frames,
download_video_frame,
download_video_frames_at_timestamps,
)
@unittest.skip("Only used for benchmarks")
class BenchmarkDownloadVideoFrames(unittest.TestCase):
... | 2,441 | 34.911765 | 120 | py |
lightly | lightly-master/tests/api/test_BitMask.py | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def test_get_and_set(self):
mask = BitMask.from_bin("0b11110000")
self.assertF... | 6,372 | 31.515306 | 80 | py |
lightly | lightly-master/tests/api/test_download.py | import json
import os
import sys
import tempfile
import unittest
import warnings
from io import BytesIO
from unittest import mock
import numpy as np
import tqdm
from PIL import Image
try:
import av
AV_AVAILABLE = True
except ImportError:
AV_AVAILABLE = False
# mock requests module so that files are read... | 23,691 | 37.90312 | 98 | py |
lightly | lightly-master/tests/api/test_patch.py | import logging
import pickle
from lightly.openapi_generated.swagger_client import Configuration
def test_make_swagger_configuration_picklable() -> None:
config = Configuration()
# Fix value to make test reproducible on systems with different number of cpus.
config.connection_pool_maxsize = 4
new_conf... | 2,017 | 37.075472 | 85 | py |
lightly | lightly-master/tests/api/test_rest_parser.py | import unittest
import numpy as np
from lightly.openapi_generated.swagger_client import (
ActiveLearningScoreCreateRequest,
ApiClient,
SamplingMethod,
ScoresApi,
)
from lightly.openapi_generated.swagger_client.rest import ApiException
class TestRestParser(unittest.TestCase):
@unittest.skip("This... | 1,593 | 39.871795 | 90 | py |
lightly | lightly-master/tests/api/test_swagger_api_client.py | import pickle
from pytest_mock import MockerFixture
from lightly.api.swagger_api_client import LightlySwaggerApiClient
from lightly.api.swagger_rest_client import LightlySwaggerRESTClientObject
from lightly.openapi_generated.swagger_client import Configuration
from lightly.openapi_generated.swagger_client.rest import... | 1,769 | 45.578947 | 97 | py |
lightly | lightly-master/tests/api/test_swagger_rest_client.py | import pickle
from pytest_mock import MockerFixture
from urllib3 import PoolManager, Timeout
from lightly.api.swagger_rest_client import LightlySwaggerRESTClientObject
from lightly.openapi_generated.swagger_client.configuration import Configuration
class TestLightlySwaggerRESTClientObject:
def test__pickle(self... | 2,933 | 39.191781 | 101 | py |
lightly | lightly-master/tests/api/test_utils.py | import os
import unittest
from unittest import mock
import pytest
from PIL import Image
from lightly.api.utils import (
DatasourceType,
PIL_to_bytes,
get_lightly_server_location_from_env,
get_signed_url_destination,
getenv,
paginate_endpoint,
retry,
)
class TestUtils(unittest.TestCase):
... | 5,647 | 36.653333 | 352 | py |
lightly | lightly-master/tests/api/test_version_checking.py | import sys
import time
import unittest
import lightly
from lightly.api.version_checking import (
LightlyAPITimeoutException,
get_latest_version,
get_minimum_compatible_version,
is_compatible_version,
is_latest_version,
pretty_print_latest_version,
)
from tests.api_workflow.mocked_api_workflow_c... | 2,524 | 32.223684 | 84 | py |
lightly | lightly-master/tests/api_workflow/__init__.py | 0 | 0 | 0 | py | |
lightly | lightly-master/tests/api_workflow/mocked_api_workflow_client.py | import csv
import io
import json
import tempfile
import unittest
from collections import defaultdict
from io import IOBase
from typing import *
import numpy as np
import requests
from requests import Response
import lightly
from lightly.api.api_workflow_client import ApiWorkflowClient
from lightly.openapi_generated.s... | 38,497 | 33.558348 | 163 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow.py | import os
from unittest import mock
import numpy as np
import lightly
from tests.api_workflow import utils
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestApiWorkflow(MockedApiWorkflowSetup):
def setUp(self) -> None:
lightl... | 4,903 | 39.528926 | 83 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_artifacts.py | import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, ArtifactNotExist
from lightly.openapi_generated.swagger_client.api import DockerApi
from lightly.openapi_generated.swagger_client.models import (
DockerRunArtifactData,
DockerRunArtifactType,
DockerRunData,
D... | 7,097 | 32.481132 | 96 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_client.py | import os
import platform
import unittest
from unittest import mock
import requests
from pytest_mock import MockerFixture
import lightly
from lightly.api.api_workflow_client import LIGHTLY_S3_SSE_KMS_KEY, ApiWorkflowClient
class TestApiWorkflowClient(unittest.TestCase):
def test_upload_file_with_signed_url(self... | 4,057 | 36.574074 | 97 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_collaboration.py | from tests.api_workflow import utils
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestApiWorkflowDatasets(MockedApiWorkflowSetup):
def setUp(self) -> None:
self.api_workflow_client = MockedApiWorkflowClient(token="token_xyz")
... | 902 | 32.444444 | 81 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_compute_worker.py | import json
import random
from typing import Any, List
from unittest import mock
from unittest.mock import MagicMock
import pytest
from pydantic import ValidationError
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_compute_worker
from lightly.api.api_workflow_compute_wor... | 33,286 | 32.931702 | 378 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_datasets.py | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasets
from lightly.openapi_generated.swagger_client.api import DatasetsApi
from lightly.openapi_generated.swagger_client.models import (
Creator,
DatasetCreateRequest,
Dat... | 19,231 | 37.931174 | 88 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_datasources.py | import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient
from lightly.openapi_generated.swagger_client.models import (
DatasourceConfigAzure,
DatasourceConfigGCS,
DatasourceConfigLOCAL,
DatasourceConfigS3,
DatasourceConfigS3DelegatedAccess,
DatasourceRawSamp... | 13,436 | 38.174927 | 104 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_download_dataset.py | import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_download_dataset
from lightly.openapi_generated.swagger_client.models import (
DatasetData,
DatasetEmbeddingData,
DatasetType,
ImageType,
TagData,
)
from tests.api_workflow import utils
def... | 10,120 | 33.42517 | 88 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_export.py | from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_export
from lightly.api import utils as api_utils
from lightly.openapi_generated.swagger_client.models import FileNameFormat, TagData
from tests.api_workflow import utils
def _get_tag(dataset_id: str, tag_name: str) -> TagD... | 10,921 | 34.232258 | 88 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_predictions.py | from unittest.mock import MagicMock, call
from lightly.api import ApiWorkflowClient
from lightly.openapi_generated.swagger_client.api import PredictionsApi
from lightly.openapi_generated.swagger_client.models import (
PredictionSingletonClassification,
PredictionTaskSchema,
PredictionTaskSchemaCategory,
... | 2,377 | 32.027778 | 113 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_selection.py | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.active_learning.config.selection_config import SelectionConfig
from lightly.api import ApiWorkflowClient, api_workflow_selection
from lightly.openapi_generated.swagger_client.models import (
JobResultType,
JobState,
J... | 7,897 | 33.33913 | 88 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_tags.py | from typing import List, Optional
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient
from lightly.api.api_workflow_tags import TagDoesNotExistError
from lightly.openapi_generated.swagger_client.models import TagCreator, TagData
from tests.api_workflow import utils
def _get... | 8,539 | 38.72093 | 88 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_upload_custom_metadata.py | from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_upload_metadata
from lightly.openapi_generated.swagger_client.models import (
SampleDataModes,
SamplePartialMode,
SampleUpdateRequest,
)
from lightly.utils.io import COCO_ANNOTATION_KEYS
from tests.api_workflow im... | 4,671 | 34.938462 | 86 | py |
lightly | lightly-master/tests/api_workflow/test_api_workflow_upload_embeddings.py | import os
import tempfile
import numpy as np
from lightly.utils import io as io_utils
from lightly.utils.io import INVALID_FILENAME_CHARACTERS
from tests.api_workflow.mocked_api_workflow_client import (
N_FILES_ON_SERVER,
MockedApiWorkflowSetup,
)
class TestApiWorkflowUploadEmbeddings(MockedApiWorkflowSetup... | 7,286 | 35.989848 | 88 | py |
lightly | lightly-master/tests/api_workflow/utils.py | import random
_CHARACTER_SET = "abcdef0123456789"
def generate_id(length: int = 24) -> str:
return "".join([random.choice(_CHARACTER_SET) for i in range(length)])
| 170 | 20.375 | 74 | py |
lightly | lightly-master/tests/cli/test_cli_crop.py | import os
import random
import re
import sys
import tempfile
import torchvision
import yaml
from hydra.experimental import compose, initialize
import lightly
from lightly.data import LightlyDataset
from lightly.utils.bounding_box import BoundingBox
from lightly.utils.cropping.crop_image_by_bounding_boxes import (
... | 5,667 | 37.040268 | 85 | py |
lightly | lightly-master/tests/cli/test_cli_download.py | import os
import sys
import tempfile
import pytest
import torchvision
from hydra.experimental import compose, initialize
import lightly
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
_DATASET_ID = "b2a40959eacd1c9a142ba57b"
class TestCLIDownlo... | 4,725 | 35.635659 | 131 | py |
lightly | lightly-master/tests/cli/test_cli_embed.py | import os
import re
import sys
import tempfile
import torchvision
from hydra.experimental import compose, initialize
import lightly
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestCLIEmbed(MockedApiWorkflowSetup):
@classmethod
... | 1,945 | 28.044776 | 88 | py |
lightly | lightly-master/tests/cli/test_cli_get_lighty_config.py | from lightly.cli.config.get_config import get_lightly_config
def test_get_lightly_config() -> None:
conf = get_lightly_config()
# Assert some default values
assert conf.checkpoint == ""
assert conf.loader.batch_size == 16
assert conf.trainer.weights_summary is None
assert conf.summary_callback... | 336 | 29.636364 | 60 | py |
lightly | lightly-master/tests/cli/test_cli_magic.py | import os
import re
import sys
import tempfile
import torchvision
from hydra.experimental import compose, initialize
from lightly import cli
from tests.api_workflow.mocked_api_workflow_client import (
N_FILES_ON_SERVER,
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestCLIMagic(MockedApiWorkf... | 2,919 | 32.953488 | 85 | py |
lightly | lightly-master/tests/cli/test_cli_train.py | import os
import re
import sys
import tempfile
import torchvision
from hydra.experimental import compose, initialize
from lightly import cli
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestCLITrain(MockedApiWorkflowSetup):
def setU... | 1,743 | 29.596491 | 85 | py |
lightly | lightly-master/tests/cli/test_cli_version.py | import os
import re
import sys
import tempfile
import pytest
from hydra.experimental import compose, initialize
from lightly.cli.version_cli import version_cli
from tests.api_workflow.mocked_api_workflow_client import (
MockedApiWorkflowClient,
MockedApiWorkflowSetup,
)
class TestCLIVersion(MockedApiWorkflo... | 789 | 25.333333 | 85 | py |
lightly | lightly-master/tests/core/test_Core.py | import os
import re
import shutil
import tempfile
import unittest
import numpy as np
import pytest
import torchvision
from lightly.core import train_model_and_embed_images
class TestCore(unittest.TestCase):
def ensure_dir(self, path_to_folder: str):
if not os.path.exists(path_to_folder):
os.... | 2,462 | 33.690141 | 86 | py |
lightly | lightly-master/tests/data/test_LightlyDataset.py | import os
import random
import re
import shutil
import tempfile
import unittest
import warnings
from typing import List, Tuple
import numpy as np
import torch
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.utils.io impor... | 15,873 | 38.984887 | 87 | py |
lightly | lightly-master/tests/data/test_LightlySubset.py | import random
import tempfile
import unittest
from typing import List, Tuple
from lightly.data.dataset import LightlyDataset
from lightly.data.lightly_subset import LightlySubset
from tests.data.test_LightlyDataset import TestLightlyDataset
try:
import av
import cv2
from lightly.data._video import VideoD... | 3,160 | 35.755814 | 84 | py |
lightly | lightly-master/tests/data/test_VideoDataset.py | import contextlib
import io
import os
import shutil
import tempfile
import unittest
from fractions import Fraction
from typing import List
from unittest import mock
import cv2
import numpy as np
import PIL
import torch
import torchvision
from lightly.data import LightlyDataset, NonIncreasingTimestampError
from lightl... | 12,849 | 36.573099 | 122 | py |
lightly | lightly-master/tests/data/test_data_collate.py | import random
import unittest
import torch
import torchvision
import torchvision.transforms as transforms
from lightly.data import (
BaseCollateFunction,
ImageCollateFunction,
MultiCropCollateFunction,
PIRLCollateFunction,
SimCLRCollateFunction,
SwaVCollateFunction,
collate,
)
from lightly... | 8,511 | 34.028807 | 81 | py |
lightly | lightly-master/tests/data/test_multi_view_collate.py | from typing import List, Tuple, Union
from warnings import warn
import torch
from torch import Tensor
from lightly.data.multi_view_collate import MultiViewCollate
def test_empty_batch():
multi_view_collate = MultiViewCollate()
batch = []
views, labels, fnames = multi_view_collate(batch)
assert len(v... | 1,391 | 29.26087 | 70 | py |
lightly | lightly-master/tests/embedding/test_callbacks.py | import pytest
from omegaconf import OmegaConf
from lightly.embedding import callbacks
def test_create_summary_callback():
summary_cb = callbacks.create_summary_callback(
summary_callback_config=OmegaConf.create({"max_depth": 99}),
trainer_config=OmegaConf.create(),
)
assert summary_cb._ma... | 1,689 | 34.957447 | 76 | py |
lightly | lightly-master/tests/embedding/test_embedding.py | import os
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torch
import torchvision
from hydra.experimental import compose, initialize
from torch import manual_seed
from torch.utils.data import DataLoader
from lightly.cli._helpers import get_model_from_config
from lightly.data ... | 2,614 | 34.337838 | 87 | py |
lightly | lightly-master/tests/loss/test_CO2Regularizer.py | import unittest
import torch
from lightly.loss.regularizer import CO2Regularizer
class TestCO2Regularizer(unittest.TestCase):
def test_forward_pass_no_memory_bank(self):
reg = CO2Regularizer(memory_bank_size=0)
for bsz in range(1, 20):
batch_1 = torch.randn((bsz, 32))
bat... | 1,708 | 30.072727 | 64 | py |
lightly | lightly-master/tests/loss/test_DCLLoss.py | import unittest
from unittest.mock import patch
import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss.dcl_loss import DCLLoss, DCLWLoss, negative_mises_fisher_weights
class TestDCLLoss:
def test__gather_distributed(self, mocker: MockerFixture) -... | 3,386 | 37.931034 | 88 | py |
lightly | lightly-master/tests/loss/test_DINOLoss.py | import copy
import itertools
import unittest
import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
from lightly.loss import DINOLoss
from lightly.models.utils import deactivate_requires_grad
class OriginalDINOLoss(nn.Module):
"""Copy paste from the original DINO paper. We use this... | 9,694 | 36.145594 | 116 | py |
lightly | lightly-master/tests/loss/test_HyperSphere.py | import unittest
import torch
from lightly.loss.hypersphere_loss import HypersphereLoss
class TestHyperSphereLoss(unittest.TestCase):
def test_forward_pass(self):
loss = HypersphereLoss()
# NOTE: skipping bsz==1 case as its not relevant to this loss, and will produce nan-values
for bsz in... | 595 | 27.380952 | 98 | py |
lightly | lightly-master/tests/loss/test_MSNLoss.py | import unittest
from unittest import TestCase
import pytest
import torch
import torch.nn.functional as F
from pytest_mock import MockerFixture
from torch import distributed as dist
from torch import nn
from torch.optim import SGD
from lightly.loss import msn_loss
from lightly.loss.msn_loss import MSNLoss
from lightly... | 6,010 | 39.073333 | 88 | py |
lightly | lightly-master/tests/loss/test_MemoryBank.py | import unittest
import torch
from lightly.loss.memory_bank import MemoryBankModule
class TestNTXentLoss(unittest.TestCase):
def test_init__negative_size(self):
with self.assertRaises(ValueError):
MemoryBankModule(size=-1)
def test_forward_easy(self):
bsz = 3
dim, size = ... | 2,029 | 30.71875 | 73 | py |
lightly | lightly-master/tests/loss/test_NTXentLoss.py | import unittest
import numpy as np
import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss import NTXentLoss
class TestNTXentLoss:
def test__gather_distributed(self, mocker: MockerFixture) -> None:
mock_is_available = mocker.patch.object(d... | 8,054 | 40.953125 | 103 | py |
lightly | lightly-master/tests/loss/test_NegativeCosineSimilarity.py | import unittest
import torch
from lightly.loss import NegativeCosineSimilarity
class TestNegativeCosineSimilarity(unittest.TestCase):
def test_forward_pass(self):
loss = NegativeCosineSimilarity()
for bsz in range(1, 20):
x0 = torch.randn((bsz, 32))
x1 = torch.randn((bsz,... | 906 | 28.258065 | 73 | py |
lightly | lightly-master/tests/loss/test_PMSNLoss.py | import math
import unittest
import pytest
import torch
from torch import Tensor
from lightly.loss import pmsn_loss
from lightly.loss.pmsn_loss import PMSNCustomLoss, PMSNLoss
class TestPMSNLoss:
def test_regularization_loss(self) -> None:
criterion = PMSNLoss()
mean_anchor_probs = torch.Tensor([... | 3,635 | 34.300971 | 87 | py |
lightly | lightly-master/tests/loss/test_SwaVLoss.py | import unittest
import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss import SwaVLoss
class TestNTXentLoss:
def test__sinkhorn_gather_distributed(self, mocker: MockerFixture) -> None:
mock_is_available = mocker.patch.object(dist, "is_ava... | 4,520 | 38.313043 | 91 | py |
lightly | lightly-master/tests/loss/test_SymNegCosineSimilarityLoss.py | import unittest
import torch
from lightly.loss import SymNegCosineSimilarityLoss
class TestSymNegCosineSimilarityLoss(unittest.TestCase):
def test_forward_pass(self):
loss = SymNegCosineSimilarityLoss()
for bsz in range(1, 20):
z0 = torch.randn((bsz, 32))
p0 = torch.randn... | 1,995 | 31.193548 | 64 | py |
lightly | lightly-master/tests/loss/test_TicoLoss.py | import unittest
import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss.tico_loss import TiCoLoss
class TestTiCoLoss:
def test__gather_distributed(self, mocker: MockerFixture) -> None:
mock_is_available = mocker.patch.object(dist, "is_avai... | 2,421 | 33.6 | 88 | py |