Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,143 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
-
library_name: mantis
|
| 4 |
-
tags:
|
| 5 |
-
- time-series-foundation-model
|
| 6 |
-
- pytorch_model_hub_mixin
|
| 7 |
-
- model_hub_mixin
|
| 8 |
-
pipeline_tag: time-series-foundation-model
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
| 4 |
|
| 5 |
+
# Mantis: Lightweight Calibrated Foundation Model for User-Friendly Time Series Classification
|
| 6 |
+
|
| 7 |
+
<p align="center">
|
| 8 |
+
<img src="https://github.com/vfeofanov/mantis/blob/main/figures/mantis_logo_white_with_font.png" alt="Logo" height="300"/>
|
| 9 |
+
</p>
|
| 10 |
+
|
| 11 |
+
## Overview
|
| 12 |
+
|
| 13 |
+
**MANTIS** is an open-source python package with a pre-trained time series classification foundation model implemented by Huawei Noah's Ark Lab.
|
| 14 |
+
|
| 15 |
+
This is a repository the model checkpoint. Please refer to the [GitHub](https://github.com/vfeofanov/mantis/tree/main) repository of the package and
|
| 16 |
+
the technical report on arxiv for more details.
|
| 17 |
+
|
| 18 |
+
## Installation
|
| 19 |
+
|
| 20 |
+
### Pip installation
|
| 21 |
+
|
| 22 |
+
> [!WARNING]
|
| 23 |
+
> The package will be released to PyPI very soon. Meanwhile, please use editable mode intallation given below.
|
| 24 |
+
>
|
| 25 |
+
|
| 26 |
+
```
|
| 27 |
+
pip install mantis
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
### Editable mode using Poetry
|
| 31 |
+
|
| 32 |
+
First, install Poetry and add the path to the binary file to your shell configuration file.
|
| 33 |
+
For example, on Linux systems, you can do this by running:
|
| 34 |
+
```bash
|
| 35 |
+
curl -sSL https://install.python-poetry.org | python3 -
|
| 36 |
+
export PATH="/home/username/.local/bin:$PATH"
|
| 37 |
+
```
|
| 38 |
+
Now you can create a virtual environment that is based on one of your already installed Python interpreters.
|
| 39 |
+
For example, if your default Python is 3.9, then create the environment by running:
|
| 40 |
+
```bash
|
| 41 |
+
poetry env use 3.9
|
| 42 |
+
```
|
| 43 |
+
Alternatively, you can specify a path to the interpreter. For example, to use an Anaconda Python interpreter:
|
| 44 |
+
```bash
|
| 45 |
+
poetry env use /path/to/anaconda3/envs/my_env/bin/python
|
| 46 |
+
```
|
| 47 |
+
If you want to run any command within the environment, instead of activating the environment manually, you can use `poetry run`:
|
| 48 |
+
```bash
|
| 49 |
+
poetry run <command>
|
| 50 |
+
```
|
| 51 |
+
For example, to install the dependencies and run tests:
|
| 52 |
+
```bash
|
| 53 |
+
poetry install
|
| 54 |
+
poetry run pytest
|
| 55 |
+
```
|
| 56 |
+
If dependencies are not resolving correctly, try re-generating the lock file:
|
| 57 |
+
```bash
|
| 58 |
+
poetry lock
|
| 59 |
+
poetry install
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
## Getting started
|
| 64 |
+
|
| 65 |
+
Please refer to [`getting_started/`](https://github.com/vfeofanov/mantis/tree/main/getting_started) to see reproducible examples of how the package can be used.
|
| 66 |
+
|
| 67 |
+
Below we summarize the basic commands needed to use the package.
|
| 68 |
+
|
| 69 |
+
### Initialization.
|
| 70 |
+
|
| 71 |
+
To load our pre-trained model from the HuggingFace, it is sufficient to run:
|
| 72 |
+
|
| 73 |
+
``` python
|
| 74 |
+
from mantis.architecture import Mantis8M
|
| 75 |
+
|
| 76 |
+
network = Mantis8M(device='cuda')
|
| 77 |
+
network = network.from_pretrained("paris-noah/Mantis-8M")
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Feature Extraction.
|
| 81 |
+
|
| 82 |
+
We provide a scikit-learn-like wrapper `MantisTrainer` that allows to use Mantis as a feature extractor by running the following commands:
|
| 83 |
+
|
| 84 |
+
``` python
|
| 85 |
+
from mantis.trainer import MantisTrainer
|
| 86 |
+
|
| 87 |
+
model = MantisTrainer(device='cuda', network=network)
|
| 88 |
+
Z = model.transform(X) # X is your time series dataset
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
### Fine-tuning.
|
| 92 |
+
|
| 93 |
+
If you want to fine-tune the model on your supervised dataset, you can use `fit` method of `MantisTrainer`:
|
| 94 |
+
|
| 95 |
+
``` python
|
| 96 |
+
from mantis.trainer import MantisTrainer
|
| 97 |
+
|
| 98 |
+
model = MantisTrainer(device='cuda', network=network)
|
| 99 |
+
model.fit(X, y) # y is a vector with class labels
|
| 100 |
+
probs = model.predict_proba(X)
|
| 101 |
+
y_pred = model.predict(X)
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Adapters.
|
| 105 |
+
|
| 106 |
+
We have integrated into the framework the possibility to pass the input to an adapter before sending it to the foundation model. This may be useful for time series data sets with a large number of channels. More specifically, large number of channels may induce the curse of dimensionality or make model's fine-tuning unfeasible.
|
| 107 |
+
|
| 108 |
+
A straightforward way to overcome these issues is to use a dimension reduction approach like PCA:
|
| 109 |
+
``` python
|
| 110 |
+
from mantis.adapters import MultichannelProjector
|
| 111 |
+
|
| 112 |
+
adapter = MultichannelProjector(new_num_channels=5, base_projector='pca')
|
| 113 |
+
adapter.fit(X)
|
| 114 |
+
X_transformed = adapter.transform(X)
|
| 115 |
+
|
| 116 |
+
model = MantisTrainer(device='cuda', network=network)
|
| 117 |
+
Z = model.transform(X_transformed)
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
Another wat is to add learnable layers before the foundation model and fine-tune them with the prediction head:
|
| 121 |
+
``` python
|
| 122 |
+
from mantis.adapters import LinearChannelCombiner
|
| 123 |
+
|
| 124 |
+
model = MantisTrainer(device='cuda', network=network)
|
| 125 |
+
adapter = LinearChannelCombiner(num_channels=X.shape[1], new_num_channels=5)
|
| 126 |
+
model.fit(X, y, adapter=adapter, fine_tuning_type='adapter_head')
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
## Citing Mantis 📚
|
| 130 |
+
|
| 131 |
+
If you use Mantis in your work, please cite this technical report:
|
| 132 |
+
|
| 133 |
+
```bibtex
|
| 134 |
+
@misc{feofanov2024mantis,
|
| 135 |
+
title={TODO},
|
| 136 |
+
author={TODO},
|
| 137 |
+
year={2024},
|
| 138 |
+
eprint={TODO},
|
| 139 |
+
archivePrefix={arXiv},
|
| 140 |
+
primaryClass={stat.ML},
|
| 141 |
+
url={TODO},
|
| 142 |
+
}
|
| 143 |
+
```
|