Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Latest commit

 

History

History
248 lines (179 loc) · 9.18 KB

File metadata and controls

248 lines (179 loc) · 9.18 KB

Content

Quick Start

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 MODEL

The 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_test

Inference: 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_test

Support

This 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.

Methods

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

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

Build Components

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.

Dataset

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:

  1. Make a Python file namedexample.py in pyanomaly/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
            '''
  2. Open the dataset_factory.py in pyanomaly/datatools/dataclass and write the following things on the top lines:

    from .example import ExampleDataset

Dataset Factory

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:

  1. Make a Python file named example_factory.py in pyanomaly/datatools/dataclass which 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
  2. Open __init__.py in pyanomaly/datatools/dataclass and write the following things:

    from .example_factory import ExampleFactory

Networks

For example, if you want to build a model named Example.

  1. Make a Python file named example_networks.py in pyanomaly/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
        '''
  2. Open the __init__.py in pyanomaly/networks/meta and add the following things:

    from .example_networks import ExampleModule
  3. Open the model_api.py in pyanomaly/networks and add the following things:

    from .meta import ExampleModule

Hooks

For example, users want to make a hook named ExampleHook

  1. Make a Python file named example_hooks.py in pyanomaly/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
  2. Open the __init__.py in pyanomaly/core/hook/functions and add the following things:

    from .example import *

Engine

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:

  1. Make a Python file named example.py in pyanomaly/core/engine/functions containing 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
  1. Open __init__.py in pyanomaly/core/engine/functions and add the following codes:
from .example import *

Loss Functions

Please refer to the codes

Evaluation functions

Please refer to the codes

Handbook

In order to help researchers and engineers, we build a Gitbook. And it will come soon.

Tools

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

Model Zoo

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.