The toolbox uses the shell file to start the training or inference process, and the parameters are as follows:
-m MODEL: The name of the method
-d DATASET: The name of the dataset
-p PROJRECT_PATH(ABSOLUTE)
-g GPUS(e.g. 0,1)
-c CONFIG_NAME
-v VERBOSE
-f(only in inference.sh) INFERENCE MODELThe name list of methods and datasets are in the MODEL ZOO
Example:
Train: use the amc in avenue
cd $PATH/TO/ROOT
sh ./script/train.sh -m amc -d avenue -p PATH/TO/ANOMALY -g 0 -c default.yaml -v train_testInference: use the amc in avenue
cd $PATH/TO/ROOT
sh ./script/inference.sh -m amc -d avenue -p PATH/TO/ANOMALY -g 0 -c default.yaml /
-f MODEL_FILE -v inference_testThis part introduces the present supported methods and the datasets in our project. The method's type is based on the taxonomy shown in the PyAnomaly: A Pytorch-based Toolkit for Video Anomaly Detection.
| Method Name | Method Type | Brief Introduction | -m parameter |
|---|---|---|---|
| STAE | Reconstruction + Prediction | It uses the differences between the reconstructed and the original to decide whether the frame is an anomaly | stae |
| AMC | Reconstruction | A method uses GAN to reconstruct the optical flow and image at the same time. | amc |
| OCAE | Reconstruction | A method mainly uses encoded features from the objects in the scene for construction. | ocae |
| AnoPred | Prediction | A method predicts the frames based on the historical information, and judges whether anomaly based on the differences between the predicted frames and the original ones. | anopred |
| AnoPCN | Reconstruction + Prediction | A method uses the RNN to reconstruct and predict at the same time. | anopcn |
| MemAE | Reconstruction | A method uses the memory mechanism to reconstruct the frames. | memae |
| Dataset Name | Brief Introduction | -d parameter |
|---|---|---|
| UCSD Ped2 | Ped2 contains 16 normal training videos and 12 testing videos | ped2 |
| Avenue | It contains 16 training and 21 testing video clips | avenue |
| ShanghaiTech Campus | It contains 330 training videos and 107 testing videos, which is captured from 13 different scenes. | shanghai |
Note: More support will come in the future, if you have the interests, please refer to the PLAN
The original intention is to promote the development of anomaly detection, so almost everything in PyAnomaly can be built by researchers and engineers. We will introduce the simple steps to build your own components. For some details, please refer to the codes.
We provide the abstract dataset class, and when users want to build the dataset, please inherit the abstract class. Meanwhile, we also provide the video and image reader tools that users can use it easily.
For example, if users want to build the dataset named Example, they should follow the steps:
-
Make a Python file named
example.pyinpyanomaly/datatools/dataclassand contains the following things:from ..abstract.video_dataset import FrameLevelVideoDataset from ..datatools_registry import DATASET_REGISTRY @DATASET_REGISTRY.register() class ExampleDataset(FrameLevelVideoDataset): def custom_step(self): ''' Step up the image loader or video loder '''
-
Open the
dataset_factory.pyinpyanomaly/datatools/dataclassand write the following things on the top lines:from .example import ExampleDataset
As shown in above, we use the Factory Designing Pattern to produce the instance of dataset class. And, specifically, we also allow the developers to use another factory instead of VideoAnomalyDatasetFactory. For example, if users want to build a factory named Example, they should follow the steps:
-
Make a Python file named
example_factory.pyinpyanomaly/datatools/dataclasswhich contains the following things:from ..datatools_registry import DATASET_FACTORY_REGISTRY from ..datatools_registry import DATASET_REGISTRY from ..abstract import AbstractDatasetFactory from DATASET_CLASS_FILES import * @DATASET_FACTORY_REGISTRY.register() class ExampleFactory(AbstractDatasetFactory): def _produce_train_dataset(self): ''' Produce the dataset for training process ''' pass def _produce_test_dataset(self): ''' Produce the dataset for inference produce ''' pass def _buid(self): ''' Call the self._produce_train_dataset and self._produce_test_dataset ''' pass
-
Open
__init__.pyinpyanomaly/datatools/dataclassand write the following things:from .example_factory import ExampleFactory
For example, if you want to build a model named Example.
-
Make a Python file named
example_networks.pyinpyanomaly/core/networks/metaand code the followings:import torch import torch.nn as nn from ..model_registry import META_ARCH_REGISTRY @META_ARCH_REGISTRY.register() class ExampleModule(nn.Module): ''' the example networks '''
-
Open the
__init__.pyinpyanomaly/networks/metaand add the following things:from .example_networks import ExampleModule
-
Open the
model_api.pyinpyanomaly/networksand add the following things:from .meta import ExampleModule
For example, users want to make a hook named ExampleHook
-
Make a Python file named
example_hooks.pyinpyanomaly/core/hook/functionsand code the followings:from ..hook_registry import HOOK_REGISTRY from ..abstract import EvaluateHook __all__ = ['ExampleHook'] @HOOK_REGISTRY.register() class ExampleHook(EvaluateHook): def evaluate(self, current_step): ''' add you own functions ''' pass
-
Open the
__init__.pyinpyanomaly/core/hook/functionsand add the following things:from .example import *
The engine means the process of training and inference. We also allow the user to make their own engine and just following the steps. For example, if you want to create the ExampleEngine, you can just follow these steps:
- Make a Python file named
example.pyinpyanomaly/core/engine/functionscontaining the following statements
from ..engine_registry import ENGINE_REGISTRY
from ..abstract.default_engine import DefaultTrainer, DefaultInference
__all__ = ['ExampleTrainer', 'ExampleInference']
@ENGINE_REGISTRY.register()
class ExampleTrainer(DefaultTrainer):
def custom_setup(self):
'''
Add you own codes here
'''
pass
def train(self):
'''
Define the specific training process
'''
pass
@ENGINE_REGISTRY.register()
class ExampleInference(DefaultInference):
def custom_setup(self):
pass
def inference(self):
pass- Open
__init__.pyinpyanomaly/core/engine/functionsand add the following codes:
from .example import *Please refer to the codes
Please refer to the codes
In order to help researchers and engineers, we build a Gitbook. And it will come soon.
During build this tool, we make some code tools to read data, make loggers, and so on. We will introduce these things here and tell the users how to use them. Some of them are referred to other repo with some modification, and we will cite the original version of them. Details are in TOOLS
In order to help researchers and engineers, we put some trained models on the Model Zoo. For the details information, please refer to the Model Zoo.