Skip to content

Commit

Permalink
Add training from a checkpoint example
Browse files Browse the repository at this point in the history
Signed-off-by: Samet Akcay <samet.akcay@intel.com>
  • Loading branch information
samet-akcay committed Oct 22, 2024
1 parent 3a403ae commit e4fe840
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
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
5 changes: 4 additions & 1 deletion docs/source/snippets/train/api/default.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Import the required modules
from anomalib.data import MVTec
from anomalib.models import Patchcore
from anomalib.engine import Engine
from anomalib.models import Patchcore

# Initialize the datamodule, model and engine
datamodule = MVTec()
Expand All @@ -10,3 +10,6 @@ engine = Engine()

# 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")
3 changes: 3 additions & 0 deletions docs/source/snippets/train/cli/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ anomalib train --model Patchcore --data anomalib.data.MVTec --data.category tran

# 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>

0 comments on commit e4fe840

Please sign in to comment.