Skip to content

Commit

Permalink
Activate mypy and fix typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
philippmwirth committed Nov 22, 2024
1 parent 4c64529 commit 1879319
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
15 changes: 6 additions & 9 deletions lightly/data/multi_view_collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,20 @@ def __call__(
If the input batch is empty, a warning is issued, and an empty tuple
`([], [], [])` is returned.
"""
labels: List[int] = []
fnames: List[str] = []

if len(batch) == 0:
warn("MultiViewCollate received empty batch.")
return [], [], []
return [], torch.tensor(labels, dtype=torch.long), fnames

views: List[List[Tensor]] = [[] for _ in range(len(batch[0][0]))]
labels = []
fnames = []
for img, label, fname in batch:
for i, view in enumerate(img):
views[i].append(view.unsqueeze(0))
labels.append(label)
fnames.append(fname)
for i, view in enumerate(views):
views[i] = torch.cat(view)

labels = torch.tensor(
labels, dtype=torch.long
) # Conversion to tensor to ensure backwards compatibility
unsqueezed_views = [torch.cat(unsqueezed_view) for unsqueezed_view in views]

return views, labels, fnames
return unsqueezed_views, torch.tensor(labels, dtype=torch.long), fnames
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,12 @@ exclude = '''(?x)(
lightly/loss/dcl_loss.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/_image.py |
lightly/data/_helpers.py |
lightly/data/_image_loaders.py |
lightly/data/_video.py |
lightly/data/_utils.py |
lightly/data/multi_view_collate.py |
lightly/core.py |
lightly/api/api_workflow_compute_worker.py |
lightly/api/api_workflow_predictions.py |
Expand Down

0 comments on commit 1879319

Please sign in to comment.