Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion configs/data/folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: segmentation
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: same_as_test
Expand Down
1 change: 0 additions & 1 deletion configs/data/mvtec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: segmentation
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: same_as_test
Expand Down
2 changes: 0 additions & 2 deletions configs/model/ai_vad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ model:
n_components_velocity: 2
n_neighbors_pose: 1
n_neighbors_deep: 1

task: detection
2 changes: 0 additions & 2 deletions configs/model/dfkde.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ model:
n_pca_components: 16
feature_scaling_method: SCALE
max_training_points: 40000

task: CLASSIFICATION
2 changes: 0 additions & 2 deletions configs/model/ganomaly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ model:
beta1: 0.5
beta2: 0.999

task: CLASSIFICATION

trainer:
max_epochs: 100
callbacks:
Expand Down
2 changes: 0 additions & 2 deletions configs/model/rkde.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ model:
n_pca_components: 16
feature_scaling_method: SCALE
max_training_points: 40000

task: detection
459 changes: 43 additions & 416 deletions notebooks/000_getting_started/001_getting_started.ipynb

Large diffs are not rendered by default.

96 changes: 14 additions & 82 deletions notebooks/100_datamodules/101_btech.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
" train_batch_size=32,\n",
" eval_batch_size=32,\n",
" num_workers=0,\n",
" task=TaskType.SEGMENTATION,\n",
")"
]
},
Expand Down Expand Up @@ -228,7 +227,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Classification Task\n"
"Now let's create the dataset, we'll start with the training subset."
]
},
{
Expand All @@ -238,49 +237,14 @@
"outputs": [],
"source": [
"# BTechDataset Classification Train Set\n",
"btech_dataset_classification_train = BTechDataset(\n",
"btech_dataset_train = BTechDataset(\n",
" root=dataset_root,\n",
" category=\"01\",\n",
" transform=transform,\n",
" split=\"train\",\n",
" task=TaskType.CLASSIFICATION,\n",
")\n",
"btech_dataset_classification_train.samples.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sample = btech_dataset_classification_train[0]\n",
"print(sample.image.shape)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"As can be seen above, when we choose `classification` task and `train` split, the dataset only returns `image`. This is mainly because training only requires normal images and no labels. Now let's try `test` split for the `classification` task\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# BTech Classification Test Set\n",
"btech_dataset_classification_test = BTechDataset(\n",
" root=dataset_root,\n",
" category=\"01\",\n",
" transform=transform,\n",
" split=\"test\",\n",
" task=TaskType.CLASSIFICATION,\n",
")\n",
"sample = btech_dataset_classification_test[0]\n",
"print(len(btech_dataset_train))\n",
"sample = btech_dataset_train[0]\n",
"print(sample.image.shape, sample.image_path, sample.gt_label)"
]
},
Expand All @@ -289,36 +253,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"where a classification test sample returns `image`, `image_path` and `label`. `image_path` is used to extract the filename when saving images.\n",
"As can be seen above, when we choose `train` split, the dataset contains 400 samples. These are the normal training samples from the \"01\" category, which have a corresponding ground truth label of `False`, indicating that the image does not contain an anomaly. \n",
"\n",
"#### Segmentation Task\n",
"\n",
"It is also possible to configure the BTech dataset for the segmentation task, where the dataset object returns image and ground-truth mask.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# BTech Segmentation Train Set\n",
"btech_dataset_segmentation_train = BTechDataset(\n",
" root=dataset_root,\n",
" category=\"01\",\n",
" transform=transform,\n",
" split=\"train\",\n",
" task=TaskType.SEGMENTATION,\n",
")\n",
"btech_dataset_segmentation_train.samples.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The above dataframe stores all the necessary information regarding the dataset. `__getitem__` method returns the corresponding information depending on the task type or train/test split.\n"
"Now let's have a look at the test set:"
]
},
{
Expand All @@ -327,16 +264,16 @@
"metadata": {},
"outputs": [],
"source": [
"# BTech Segmentation Test Set\n",
"btech_dataset_segmentation_test = BTechDataset(\n",
"# BTech Classification Test Set\n",
"btech_dataset_test = BTechDataset(\n",
" root=dataset_root,\n",
" category=\"01\",\n",
" transform=transform,\n",
" split=\"test\",\n",
" task=TaskType.SEGMENTATION,\n",
")\n",
"sample = btech_dataset_segmentation_test[20]\n",
"print(sample.image.shape, sample.gt_mask.shape)"
"print(len(btech_dataset_test))\n",
"sample = btech_dataset_test[0]\n",
"print(sample.image.shape, sample.image_path, sample.gt_label)"
]
},
{
Expand All @@ -363,7 +300,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "anomalib",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -377,14 +314,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.14"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "ae223df28f60859a2f400fae8b3a1034248e0a469f5599fd9a89c32908ed7a84"
}
}
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
91 changes: 16 additions & 75 deletions notebooks/100_datamodules/102_mvtec.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"from torchvision.transforms.v2 import Resize\n",
"from torchvision.transforms.v2.functional import to_pil_image\n",
"\n",
"from anomalib.data import MVTec, MVTecDataset\n",
"from anomalib import TaskType"
"from anomalib.data import MVTec, MVTecDataset"
]
},
{
Expand Down Expand Up @@ -87,7 +86,6 @@
" train_batch_size=32,\n",
" eval_batch_size=32,\n",
" num_workers=0,\n",
" task=TaskType.SEGMENTATION,\n",
")"
]
},
Expand Down Expand Up @@ -206,7 +204,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Classification Task\n"
"Now let's create the dataset, we'll start with the training subset."
]
},
{
Expand All @@ -215,50 +213,15 @@
"metadata": {},
"outputs": [],
"source": [
"# MVTec Classification Train Set\n",
"mvtec_dataset_classification_train = MVTecDataset(\n",
"# MVTec dataset\n",
"mvtec_dataset_train = MVTecDataset(\n",
" root=dataset_root,\n",
" category=\"bottle\",\n",
" transform=transform,\n",
" split=\"train\",\n",
" task=\"classification\",\n",
")\n",
"mvtec_dataset_classification_train.samples.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sample = mvtec_dataset_classification_train[0]\n",
"print(sample.image.shape)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"As can be seen above, when we choose `classification` task and `train` split, the dataset only returns `image`. This is mainly because training only requires normal images and no labels. Now let's try `test` split for the `classification` task\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# MVTec Classification Test Set\n",
"mvtec_dataset_classification_test = MVTecDataset(\n",
" root=dataset_root,\n",
" category=\"bottle\",\n",
" transform=transform,\n",
" split=\"test\",\n",
" task=\"classification\",\n",
")\n",
"sample = mvtec_dataset_classification_test[0]\n",
"print(len(mvtec_dataset_train))\n",
"sample = mvtec_dataset_train[0]\n",
"print(sample.image.shape, sample.image_path, sample.gt_label)"
]
},
Expand All @@ -267,26 +230,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Segmentation Task\n",
"As can be seen above, when we choose `train` split, the dataset contains 209 samples. These are the normal training samples from the MVTec bottle category, which have a corresponding ground truth label of `False`, indicating that the image does not contain an anomaly. \n",
"\n",
"It is also possible to configure the MVTec dataset for the segmentation task, where the dataset object returns image and ground-truth mask.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# MVTec Segmentation Train Set\n",
"mvtec_dataset_segmentation_train = MVTecDataset(\n",
" root=dataset_root,\n",
" category=\"bottle\",\n",
" transform=transform,\n",
" split=\"train\",\n",
" task=\"segmentation\",\n",
")\n",
"mvtec_dataset_segmentation_train.samples.head()"
"Now let's have a look at the test set:\n"
]
},
{
Expand All @@ -295,16 +241,16 @@
"metadata": {},
"outputs": [],
"source": [
"# MVTec Segmentation Test Set\n",
"mvtec_dataset_segmentation_test = MVTecDataset(\n",
"# MVTec Classification Test Set\n",
"mvtec_dataset_test = MVTecDataset(\n",
" root=dataset_root,\n",
" category=\"bottle\",\n",
" transform=transform,\n",
" split=\"test\",\n",
" task=\"segmentation\",\n",
")\n",
"sample = mvtec_dataset_segmentation_test[20]\n",
"print(sample.image.shape, sample.gt_mask.shape)"
"print(len(mvtec_dataset_test))\n",
"sample = mvtec_dataset_test[0]\n",
"print(sample.image.shape, sample.image_path, sample.gt_label)"
]
},
{
Expand All @@ -330,7 +276,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "anomalib",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -344,14 +290,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.14"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "ae223df28f60859a2f400fae8b3a1034248e0a469f5599fd9a89c32908ed7a84"
}
}
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Loading