Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mvtec 3d #907

Merged
merged 36 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c4d2666
add heat map to classification
alexriedel1 Aug 26, 2022
ec439c4
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Aug 30, 2022
27e7cd3
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Sep 5, 2022
0ceeb3d
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Sep 15, 2022
7a93f91
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Sep 26, 2022
f7bdf89
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Oct 12, 2022
63792dd
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Oct 18, 2022
e46d625
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Nov 8, 2022
e86f9c2
fix assertion if no masks are provided
alexriedel1 Nov 8, 2022
e1fe3ff
Merge branch 'openvinotoolkit:main' into main
alexriedel1 Feb 2, 2023
35e50ce
first commit mvtec3d
alexriedel1 Feb 2, 2023
b8ec0ba
main test
alexriedel1 Feb 2, 2023
95945cc
construct filename df
alexriedel1 Feb 2, 2023
9ada94e
mvtec 3d implemented
alexriedel1 Feb 7, 2023
67b00eb
Merge branch 'openvinotoolkit:main' into mvtec_3d
alexriedel1 Feb 7, 2023
8f969d0
folder dataset 3d ready
alexriedel1 Feb 7, 2023
9bd958e
Merge branch 'mvtec_3d' of https://github.com/alexriedel1/anomalib in…
alexriedel1 Feb 7, 2023
e8fb5f4
folder dataset 3d
alexriedel1 Feb 10, 2023
131833b
Merge branch 'openvinotoolkit:main' into mvtec_3d
alexriedel1 Feb 10, 2023
81bcd06
folder 3d separate
alexriedel1 Feb 11, 2023
b172760
original folder
alexriedel1 Feb 11, 2023
0127fe1
folder 3d remove test
alexriedel1 Feb 11, 2023
3494d18
fix typings
alexriedel1 Feb 11, 2023
30bb724
Merge branch 'openvinotoolkit:main' into mvtec_3d
alexriedel1 Feb 15, 2023
468efbb
fix debugging artefacts
alexriedel1 Feb 15, 2023
e7d1a53
original folder
alexriedel1 Feb 15, 2023
b1b1b83
Merge branch 'openvinotoolkit:main' into mvtec_3d
alexriedel1 Feb 26, 2023
f057d59
depth map classification visualizer, add CLI
alexriedel1 Feb 26, 2023
2e98258
folder logic same as folder_3d logic
alexriedel1 Feb 26, 2023
6f3d894
pre commit
alexriedel1 Feb 26, 2023
7e10fd4
notebook reset, typo, move functions
alexriedel1 Mar 1, 2023
116a734
files added
alexriedel1 Mar 1, 2023
44c28ed
Merge branch 'main' into mvtec_3d
samet-akcay Mar 1, 2023
2ff3027
pre commit fixing
alexriedel1 Mar 1, 2023
4d52801
Merge branch 'mvtec_3d' of https://github.com/alexriedel1/anomalib in…
alexriedel1 Mar 1, 2023
1b33a55
new pre commits
alexriedel1 Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ repos:
- id: nbqa-flake8
- id: nbqa-pylint

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
#- repo: https://github.com/pre-commit/mirrors-prettier
# rev: v2.7.1
# hooks:
# - id: prettier

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.2
hooks:
- id: markdownlint
#- repo: https://github.com/igorshubovych/markdownlint-cli
# rev: v0.32.2
# hooks:
# - id: markdownlint

- repo: https://github.com/AleksaC/hadolint-py
rev: v2.10.0
Expand Down
4 changes: 4 additions & 0 deletions anomalib/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from .base import AnomalibDataModule, AnomalibDataset
from .btech import BTech
from .folder import Folder
from .folder_3d import Folder3D
from .inference import InferenceDataset
from .mvtec import MVTec
from .mvtec_3d import MVTec3D
from .shanghaitech import ShanghaiTech
from .task_type import TaskType
from .ucsd_ped import UCSDped
Expand Down Expand Up @@ -187,8 +189,10 @@ def get_datamodule(config: DictConfig | ListConfig) -> AnomalibDataModule:
"get_datamodule",
"BTech",
"Folder",
"Folder3D",
"InferenceDataset",
"MVTec",
"MVTec3D",
"Avenue",
"UCSDped",
"TaskType",
Expand Down
9 changes: 8 additions & 1 deletion anomalib/data/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

from .datamodule import AnomalibDataModule
from .dataset import AnomalibDataset
from .depth import AnomalibDepthDataset
from .video import AnomalibVideoDataModule, AnomalibVideoDataset

__all__ = ["AnomalibDataset", "AnomalibDataModule", "AnomalibVideoDataset", "AnomalibVideoDataModule"]
__all__ = [
"AnomalibDataset",
"AnomalibDataModule",
"AnomalibVideoDataset",
"AnomalibVideoDataModule",
"AnomalibDepthDataset",
]
2 changes: 1 addition & 1 deletion anomalib/data/base/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pandas import DataFrame
from pytorch_lightning import LightningDataModule
from pytorch_lightning.utilities.types import EVAL_DATALOADERS, TRAIN_DATALOADERS
from torch.utils.data import DataLoader, default_collate
from torch.utils.data.dataloader import DataLoader, default_collate

from anomalib.data.base.dataset import AnomalibDataset
from anomalib.data.synthetic import SyntheticAnomalyDataset
Expand Down
3 changes: 2 additions & 1 deletion anomalib/data/base/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ def __getitem__(self, index: int) -> dict[str, str | Tensor]:

image = read_image(image_path)
item = dict(image_path=image_path, label=label_index)

print(mask_path, label_index)
if self.task == TaskType.CLASSIFICATION:
transformed = self.transform(image=image)
item["image"] = transformed["image"]
elif self.task in (TaskType.DETECTION, TaskType.SEGMENTATION):
# Only Anomalous (1) images have masks in anomaly datasets
# Therefore, create empty mask for Normal (0) images.

if label_index == 0:
mask = np.zeros(shape=image.shape[:2])
else:
Expand Down
68 changes: 68 additions & 0 deletions anomalib/data/base/depth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Base Depth Dataset."""

from __future__ import annotations

from abc import ABC

import albumentations as A
import cv2
import numpy as np
from torch import Tensor

from anomalib.data.base.dataset import AnomalibDataset
from anomalib.data.task_type import TaskType
from anomalib.data.utils import masks_to_boxes, read_depth_image, read_image


class AnomalibDepthDataset(AnomalibDataset, ABC):
"""Base depth anomalib dataset class.

Args:
task (str): Task type, either 'classification' or 'segmentation'
transform (A.Compose): Albumentations Compose object describing the transforms that are applied to the inputs.
"""

def __init__(self, task: TaskType, transform: A.Compose) -> None:
super().__init__(task, transform)

self.transform = transform

def __getitem__(self, index: int) -> dict[str, str | Tensor]:
"""Return rgb image, depth image and mask."""

image_path = self._samples.iloc[index].image_path
mask_path = self._samples.iloc[index].mask_path
label_index = self._samples.iloc[index].label_index
depth_path = self._samples.iloc[index].depth_path

image = read_image(image_path)
depth_image = read_depth_image(depth_path)
item = dict(image_path=image_path, depth_path=depth_path, label=label_index)

if self.task == TaskType.CLASSIFICATION:
transformed = self.transform(image=image, depth_image=depth_image)
item["image"] = transformed["image"]
item["depth_image"] = transformed["depth_image"]
elif self.task in (TaskType.DETECTION, TaskType.SEGMENTATION):
# Only Anomalous (1) images have masks in anomaly datasets
# Therefore, create empty mask for Normal (0) images.
if label_index == 0:
mask = np.zeros(shape=image.shape[:2])
else:
mask = cv2.imread(mask_path, flags=0) / 255.0

transformed = self.transform(image=image, depth_image=depth_image, mask=mask)

item["image"] = transformed["image"]
item["depth_image"] = transformed["depth_image"]
item["mask_path"] = mask_path
item["mask"] = transformed["mask"]

if self.task == TaskType.DETECTION:
# create boxes from masks for detection task
boxes, _ = masks_to_boxes(item["mask"])
item["boxes"] = boxes[0]
else:
raise ValueError(f"Unknown task type: {self.task}")

return item
Loading