summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Codes/checkpoints/download_pretrains.sh11
-rw-r--r--Codes/constant.py6
-rw-r--r--Codes/models/download_pretrains.sh11
-rw-r--r--Codes/requirements.txt2
-rw-r--r--Codes/utils.py86
-rw-r--r--README.md14
6 files changed, 32 insertions, 98 deletions
diff --git a/Codes/checkpoints/download_pretrains.sh b/Codes/checkpoints/download_pretrains.sh
new file mode 100644
index 0000000..a85f19c
--- /dev/null
+++ b/Codes/checkpoints/download_pretrains.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+echo "Downloading trained models on ped1, ped2 and avenue datasets ....."
+
+wget "https://ofhz9a.bn.files.1drv.com/y4mdc9K-lh3tfqBXiG-rSR04JARM20at-t2AtTo-7fUC-fadMB_x255o35v0J-YV4bnMW9m9XscVOKkITHI2bZLrgxZJJKXI4QEVDsi61KvsLQxI42elYWmm01F2kjI94onmbRrFYai7CkVNUspBgscY2vvEfd2c3qE2A_bcTW-Cp_6hBKpPEQClmwlT2QqTy-UwuzCmjyFfOrHqKeGkqtadQ/pretrains.tar.gz"
+tar -xvf pretrains.tar.gz
+rm pretrains.tar.gz
+
+echo "Download pretrains successfully..."
+
+
diff --git a/Codes/constant.py b/Codes/constant.py
index f6f78df..b4fc7e3 100644
--- a/Codes/constant.py
+++ b/Codes/constant.py
@@ -92,7 +92,7 @@ const.EVALUATE = args.evaluate
# network constants
const.HEIGHT = 256
const.WIDTH = 256
-const.FLOWNET_CHECKPOINT = 'models/pretrains/flownet-SD.ckpt-0'
+const.FLOWNET_CHECKPOINT = 'checkpoints/pretrains/flownet-SD.ckpt-0'
const.FLOW_HEIGHT = 384
const.FLOW_WIDTH = 512
@@ -136,9 +136,9 @@ if args.snapshot_dir:
const.SNAPSHOT_DIR = args.snapshot_dir
print(const.SNAPSHOT_DIR)
else:
- const.SNAPSHOT_DIR = get_dir(os.path.join('models', const.SAVE_DIR + '_' + args.snapshot_dir))
+ const.SNAPSHOT_DIR = get_dir(os.path.join('checkpoints', const.SAVE_DIR + '_' + args.snapshot_dir))
else:
- const.SNAPSHOT_DIR = get_dir(os.path.join('models', const.SAVE_DIR))
+ const.SNAPSHOT_DIR = get_dir(os.path.join('checkpoints', const.SAVE_DIR))
if args.summary_dir:
const.SUMMARY_DIR = get_dir(os.path.join('summary', const.SAVE_DIR + '_' + args.summary_dir))
diff --git a/Codes/models/download_pretrains.sh b/Codes/models/download_pretrains.sh
deleted file mode 100644
index d2a7da8..0000000
--- a/Codes/models/download_pretrains.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-echo "Downloading trained models on ped1, ped2 and avenue datasets ....."
-
-wget "https://ofhz9a.bn.files.1drv.com/y4mljH6-fb1fLS6B9cJg5kst-wanKhmgoA8mWk_8y8atGlL4SQqEqZRljA8LuLkxkvm-36PArbAsx-uYKxzfUX1s8otO8h0Rv7tag9Agx1h8_RsTPhQo-aft0QSybwpvcvOkegqfLVg2UJjTzIsxgizIYCVDIpunmpasyB3t4mchRGZetZQGiKP4fS2Vfb4c3tj1jxzpN61Pmou9QaB3VAG0w/pretrains.tar.gz"
-tar -xvf pretrains.tar.gz
-rm pretrains.tar.gz
-
-echo "Download pretrains successfully..."
-
-
diff --git a/Codes/requirements.txt b/Codes/requirements.txt
index 91d2206..8ab8d6c 100644
--- a/Codes/requirements.txt
+++ b/Codes/requirements.txt
@@ -2,7 +2,7 @@ numpy==1.14.1
scipy==1.0.0
matplotlib==2.1.2
tensorflow==1.4.1
-tensorflow_gpu==1.4.1
+tensorflow-gpu==1.4.1
Pillow==5.0.0
pypng==0.0.18
scikit_learn==0.19.1
diff --git a/Codes/utils.py b/Codes/utils.py
index efeab8e..8466d08 100644
--- a/Codes/utils.py
+++ b/Codes/utils.py
@@ -10,6 +10,15 @@ rng = np.random.RandomState(2017)
def np_load_frame(filename, resize_height, resize_width):
+ """
+ Load image path and convert it to numpy.ndarray. Notes that the color channels are BGR and the color space
+ is normalized from [0, 255] to [-1, 1].
+
+ :param filename: the full path of image
+ :param resize_height: resized height
+ :param resize_width: resized width
+ :return: numpy.ndarray
+ """
image_decoded = cv2.imread(filename)
image_resized = cv2.resize(image_decoded, (resize_width, resize_height))
image_resized = image_resized.astype(dtype=np.float32)
@@ -20,7 +29,7 @@ def np_load_frame(filename, resize_height, resize_width):
class DataLoader(object):
def __init__(self, video_folder, resize_height=256, resize_width=256):
self.dir = video_folder
- self.videos = {}
+ self.videos = OrderedDict()
self._resize_height = resize_height
self._resize_width = resize_width
self.setup()
@@ -83,15 +92,6 @@ class DataLoader(object):
return np.concatenate(batch, axis=2)
- # def get_video_clips(self, video_name, start, end):
- # video_idx = np.arange(start, end)
- # video_clip = np.empty(shape=[self._resize_height, self._resize_height, 3*len(video_idx)], dtype=np.float32)
- # for idx, v_idx in enumerate(video_idx):
- # filename = self.videos[video_name]['frame'][v_idx]
- # video_clip[..., idx*3:(idx+1)*3] = np_load_frame(filename, self._resize_height, self._resize_width)
- #
- # return video_clip
-
def log10(t):
"""
@@ -130,46 +130,6 @@ def psnr_error(gen_frames, gt_frames):
return tf.reduce_mean(batch_errors)
-def sharp_diff_error(gen_frames, gt_frames, channels=3):
- """
- Computes the Sharpness Difference error between the generated images and the ground truth
- images.
-
- @param gen_frames: A tensor of shape [batch_size, height, width, 3]. The frames generated by the
- generator model.
- @param gt_frames: A tensor of shape [batch_size, height, width, 3]. The ground-truth frames for
- each frame in gen_frames.
- @param channels: The number of channels, 3 is RGB and 1 is Gray, default is 3.
-
- @return: A scalar tensor. The Sharpness Difference error over each frame in the batch.
- """
- shape = tf.shape(gen_frames)
- num_pixels = tf.to_float(shape[1] * shape[2] * shape[3])
-
- # gradient difference
- # create filters [-1, 1] and [[1],[-1]] for diffing to the left and down respectively.
- # TODO: Could this be simplified with one filter [[-1, 2], [0, -1]]?
- pos = tf.constant(np.identity(channels), dtype=tf.float32)
- neg = -1 * pos
- filter_x = tf.expand_dims(tf.stack([neg, pos]), 0) # [-1, 1]
- filter_y = tf.stack([tf.expand_dims(pos, 0), tf.expand_dims(neg, 0)]) # [[1],[-1]]
- strides = [1, 1, 1, 1] # stride of (1, 1)
- padding = 'SAME'
-
- gen_dx = tf.abs(tf.nn.conv2d(gen_frames, filter_x, strides, padding=padding))
- gen_dy = tf.abs(tf.nn.conv2d(gen_frames, filter_y, strides, padding=padding))
- gt_dx = tf.abs(tf.nn.conv2d(gt_frames, filter_x, strides, padding=padding))
- gt_dy = tf.abs(tf.nn.conv2d(gt_frames, filter_y, strides, padding=padding))
-
- gen_grad_sum = gen_dx + gen_dy
- gt_grad_sum = gt_dx + gt_dy
-
- grad_diff = tf.abs(gt_grad_sum - gen_grad_sum)
-
- batch_errors = 10 * log10(1 / ((1 / num_pixels) * tf.reduce_sum(grad_diff, [1, 2, 3])))
- return tf.reduce_mean(batch_errors)
-
-
def diff_mask(gen_frames, gt_frames, min_value=-1, max_value=1):
# normalize to [0, 1]
delta = max_value - min_value
@@ -197,31 +157,5 @@ def save(saver, sess, logdir, step):
print('The checkpoint has been created.')
-# if __name__ == '__main__':
-# os.environ['CUDA_DEVICES_ORDER'] = "PCI_BUS_ID"
-# os.environ['CUDA_VISIBLE_DEVICES'] = '0'
-#
-# data_loader = DataLoader('/home/liuwen/ssd/datasets/avenue/training/frames')
-# dataset, epoch_size = data_loader(10, 4, 1, 3, 1)
-#
-# # debug
-# iteration = dataset.make_one_shot_iterator()
-# batch_video_clip_tensor = iteration.get_next()
-#
-# config = tf.ConfigProto()
-# config.gpu_options.allow_growth = True
-# with tf.Session(config=config) as sess:
-# # batch_video_clip = sess.run(next(it))
-#
-# for i in range(100):
-# batch_video_clip = sess.run(batch_video_clip_tensor)
-# # print(batch_video_clip.shape)
-#
-# for vid, video_clip in enumerate(batch_video_clip):
-# for fid, frame in enumerate(video_clip):
-# print(i, vid, fid)
-# cv2.imshow('visualization', frame + 0.5)
-# cv2.waitKey(100)
-
diff --git a/README.md b/README.md
index 65af431..ea81bd2 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# Future Frame Prediction for Anomaly Detection -- A New Baseline
-This repo is the official open source of [Future Frame Prediction for Anomaly Detection -- A New Baseline, CVPR 2018](https://arxiv.org/pdf/1712.09867.pdf) by Wen Liu, Weixinluo, Dongze Lian and Shenghua Gao.
+This repo is the official open source of [Future Frame Prediction for Anomaly Detection -- A New Baseline, CVPR 2018](https://arxiv.org/pdf/1712.09867.pdf) by Wen Liu, Weixin Lluo, Dongze Lian and Shenghua Gao.
A **demo** is shown in *https://www.youtube.com/watch?v=M--wv-Y_h0A*. It is implemented in tensorflow. Please follow the instructions to run the code.
## 1. Installation (Anaconda with python3.6 installation is recommended)
@@ -8,7 +8,7 @@ A **demo** is shown in *https://www.youtube.com/watch?v=M--wv-Y_h0A*. It is impl
numpy==1.14.1
scipy==1.0.0
matplotlib==2.1.2
-tensorflow_gpu==1.4.1
+tensorflow-gpu==1.4.1
tensorflow==1.4.1
Pillow==5.0.0
pypng==0.0.18
@@ -37,7 +37,7 @@ cd Data
## 3. Testing on saved models
* Download the trained models
```shell
-cd models
+cd checkpoints
./download_pretrains.sh
```
* Running the sript (as ped2 and avenue datasets for examples) and cd into **Codes** folder at first.
@@ -45,14 +45,14 @@ cd models
python inference.py --dataset ped2 \
--test_folder ../Data/ped2/testing/frames \
--gpu 1 \
- --snapshot_dir models/pretrains/ped2
+ --snapshot_dir checkpoints/pretrains/ped2
```
```shell
python inference.py --dataset avenue \
--test_folder ../Data/avenue/testing/frames \
--gpu 1 \
- --snapshot_dir models/pretrains/avenue
+ --snapshot_dir checkpoints/pretrains/avenue
```
@@ -111,8 +111,8 @@ Open the browser and type **https://ip:10086**. Following is the screen shot of
![scalars_tensorboard](assets/scalars.JPG)
![images_tensorboard](assets/images.JPG)
-Since all frames are loaded into BGR channels in training and testing, the visualized images look different from RGB channels.
-
+Since the models are trained in BGR image color channels, the visualized images in tensorboard look different from RGB channels.
+In the demo, we change the output images from BGR to RGB.
## Notes
The flow loss (temporal loss) module is based on [a TensorFlow implementation of FlowNet2](https://github.com/sampepose/flownet2-tf). Thanks for their nice work.