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

πŸ“š Add training from a checkpoint example #2389

Merged
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
30 changes: 16 additions & 14 deletions docs/source/markdown/get_started/anomalib.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The installer can be installed using the following commands:
:::{tab-item} API
:sync: label-1

```{literalinclude} ../../snippets/install/pypi.txt
```{literalinclude} /snippets/install/pypi.txt
:language: bash
```

Expand All @@ -26,7 +26,7 @@ The installer can be installed using the following commands:
:::{tab-item} Source
:sync: label-2

```{literalinclude} ../../snippets/install/source.txt
```{literalinclude} /snippets/install/source.txt
:language: bash
```

Expand All @@ -42,22 +42,22 @@ The next section demonstrates how to install the full package using the CLI inst
:::::{dropdown} Installing the Full Package
After installing anomalib, you can install the full package using the following commands:

```{literalinclude} ../../snippets/install/anomalib_help.txt
```{literalinclude} /snippets/install/anomalib_help.txt
:language: bash
```

As can be seen above, the only available sub-command is `install` at the moment.
The `install` sub-command has options to install either the full package or the
specific components of the package.

```{literalinclude} ../../snippets/install/anomalib_install_help.txt
```{literalinclude} /snippets/install/anomalib_install_help.txt
:language: bash
```

By default the `install` sub-command installs the full package. If you want to
install only the specific components of the package, you can use the `--option` flag.

```{literalinclude} ../../snippets/install/anomalib_install.txt
```{literalinclude} /snippets/install/anomalib_install.txt
:language: bash
```

Expand All @@ -66,21 +66,23 @@ After following these steps, your environment will be ready to use anomalib!

## {octicon}`mortar-board` Training

Anomalib supports both API and CLI-based training. The API is more flexible and allows for more customization, while the CLI training utilizes command line interfaces, and might be easier for those who would like to use anomalib off-the-shelf.
Anomalib supports both API and CLI-based training. The API is more flexible
and allows for more customization, while the CLI training utilizes command line
interfaces, and might be easier for those who would like to use anomalib off-the-shelf.

::::{tab-set}

:::{tab-item} API

```{literalinclude} ../../snippets/train/api/default.txt
```{literalinclude} /snippets/train/api/default.txt
:language: python
```

:::

:::{tab-item} CLI

```{literalinclude} ../../snippets/train/cli/default.txt
```{literalinclude} /snippets/train/cli/default.txt
:language: bash
```

Expand All @@ -100,7 +102,7 @@ Anomalib includes multiple inferencing scripts, including Torch, Lightning, Grad
:::{tab-item} API
:sync: label-1

```{literalinclude} ../../snippets/inference/api/lightning.txt
```{literalinclude} /snippets/inference/api/lightning.txt
:language: python
```

Expand All @@ -109,7 +111,7 @@ Anomalib includes multiple inferencing scripts, including Torch, Lightning, Grad
:::{tab-item} CLI
:sync: label-2

```{literalinclude} ../../snippets/inference/cli/lightning.txt
```{literalinclude} /snippets/inference/cli/lightning.txt
:language: bash
```

Expand Down Expand Up @@ -201,15 +203,15 @@ Anomalib supports hyper-parameter optimization using [wandb](https://wandb.ai/)

:::{tab-item} CLI

```{literalinclude} ../../snippets/pipelines/hpo/cli.txt
```{literalinclude} /snippets/pipelines/hpo/cli.txt
:language: bash
```

:::

:::{tab-item} API

```{literalinclude} ../../snippets/pipelines/hpo/api.txt
```{literalinclude} /snippets/pipelines/hpo/api.txt
:language: bash
```

Expand All @@ -233,15 +235,15 @@ To run a training experiment with experiment tracking, you will need the followi

By using the configuration file above, you can run the experiment with the following command:

```{literalinclude} ../../snippets/logging/cli.txt
```{literalinclude} /snippets/logging/cli.txt
:language: bash
```

:::

:::{tab-item} API

```{literalinclude} ../../snippets/logging/api.txt
```{literalinclude} /snippets/logging/api.txt
:language: bash
```

Expand Down
11 changes: 7 additions & 4 deletions docs/source/snippets/train/api/default.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Import the required modules
from anomalib.data import MVTec
from anomalib.models import Patchcore
from anomalib.engine import Engine
from anomalib.models import EfficientAd

# Initialize the datamodule, model and engine
datamodule = MVTec()
model = Patchcore()
engine = Engine()
datamodule = MVTec(train_batch_size=1)
model = EfficientAd()
engine = Engine(max_epochs=5)

# Train the model
engine.fit(datamodule=datamodule, model=model)

# Continue from a checkpoint
engine.fit(datamodule=datamodule, model=model, ckpt_path="path/to/checkpoint.ckpt")
ashwinvaidya17 marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions docs/source/snippets/train/cli/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
anomalib train -h

# Train by using the default values.
anomalib train --model Patchcore --data anomalib.data.MVTec
anomalib train --model EfficientAd --data anomalib.data.MVTec --data.train_batch_size 1

# Train by overriding arguments.
anomalib train --model Patchcore --data anomalib.data.MVTec --data.category transistor
anomalib train --model EfficientAd --data anomalib.data.MVTec --data.train_batch_size 1 --data.category transistor

# Train by using a config file.
anomalib train --config <path/to/config>

# Continue training from a checkpoint
anomalib train --config <path/to/config> --ckpt_path <path/to/checkpoint.ckpt>
Loading