/Anomaly_Prediction

Pytorch implementation of anomaly prediction.

Primary LanguagePython

Anomaly_Prediction

Pytorch implementation of anomaly prediction for CVPR2018:Future Frame Prediction for Anomaly Detection – A New Baseline.
This implementation used lite-flownet instead of Flownet2SD and the generator network is slightly different.
I only trained the ped2 and avenue datasets, the results:

AUC USCD Ped2 CUHK Avenue
original implementation 95.4% 84.9%
this implementation 95.6% 84.6%

The network pipeline.

Example 0

Environments

PyTorch >= 1.1.
Python >= 3.6.
tensorboardX
cupy
sklearn
Other common packages.

Prepare

  • Download the ped2 and avenue datasets.
USCD Ped2 CUHK Avenue
Google Drive Google Drive
Baidu Cloud: e0qj Baidu Cloud: ufq6
  • Modify 'data_root' in config.py, and then unzip the datasets under your data root.
  • Download the lite-flownet model and put it under the 'models/liteFlownet' folder, or the Flownet2SD model under the 'models/flownet2' folder.
network-default.pytorch FlowNet2-SD.pth
Google Drive Google Drive
Baidu Cloud: auqh Baidu Cloud: v7qr
  • Download the trained model and put them under the 'weights' folder.
ped2_26000.pth avenue_15000.pth
Google Drive Google Drive
Baidu Cloud: 5hu9 Baidu Cloud: 92d8

Train

# Train by default with specified dataset.
python train.py --dataset=avenue
# Train with different batch_size, you might need to tune the learning rate by yourself.
python train.py --dataset=avenue --batch_size=16
# Set the max training iterations.
python train.py --dataset=avenue --iters=80000
# Set the save interval and the validation interval.
python train.py --dataset=avenue --save_interval=2000 --val_interval=2000
# Resume training with the latest trained model or a specified model.
python train.py --dataset=avenue --resume latest [or avenue_10000.pth]
# Train with Flownet2SD instead of lite-flownet.
python train.py --dataset=avenue --flownet=2sd
# Visualize the optic flow during training.
python train.py --dataset=avenue --show_flow

Use tensorboard

tensorboard --logdir=tensorboard_log/ped2_bs4

Example 1

Evalution

# Validate with a trained model.
python evaluate.py --dataset=ped2 --trained_model=ped2_26000.pth
# Show and save the psnr curve and the difference heatmap between the gt frame and the 
# generated frame during evaluating. This drops fps.
python evaluate.py --dataset=ped2 --trained_model=ped2_26000.pth --show_curve --show_heatmap

Example 2