summaryrefslogtreecommitdiff
path: root/Codes
diff options
context:
space:
mode:
Diffstat (limited to 'Codes')
-rw-r--r--Codes/evaluate.py15
-rw-r--r--Codes/inference-test.py21
-rw-r--r--Codes/test.sh12
-rw-r--r--Codes/train.sh6
-rw-r--r--Codes/training_hyper_params/hyper_params.ini46
-rw-r--r--Codes/utils.py2
6 files changed, 92 insertions, 10 deletions
diff --git a/Codes/evaluate.py b/Codes/evaluate.py
index cd0fcef..4909e50 100644
--- a/Codes/evaluate.py
+++ b/Codes/evaluate.py
@@ -114,8 +114,10 @@ class GroundTruthLoader(object):
gt = self.__load_shanghaitech_gt()
elif dataset == GroundTruthLoader.TOY_DATA:
gt = self.__load_toydata_gt()
+ #else:
+ # gt = self.__load_ucsd_avenue_subway_gt(dataset)
else:
- gt = self.__load_ucsd_avenue_subway_gt(dataset)
+ gt = self.__load_no_anomaly_gt(dataset)
return gt
def __load_ucsd_avenue_subway_gt(self, dataset):
@@ -200,6 +202,15 @@ class GroundTruthLoader(object):
return gt
@staticmethod
+ def __load_no_anomaly_gt():
+ gt = []
+ for i in xrange(27):
+ length = 64
+ video_gt = np.zeros((length,), dtype=np.uint8)
+ gt.append(video_gt)
+ return gt
+
+ @staticmethod
def get_pixel_masks_file_list(dataset):
# pixel mask folder
pixel_mask_folder = os.path.join(DATA_DIR, dataset, 'pixel_masks')
@@ -573,4 +584,4 @@ if __name__ == '__main__':
if eval_type == 'test_func':
test_func()
else:
- evaluate(eval_type, file_path) \ No newline at end of file
+ evaluate(eval_type, file_path)
diff --git a/Codes/inference-test.py b/Codes/inference-test.py
index b16a56c..83a4fd4 100644
--- a/Codes/inference-test.py
+++ b/Codes/inference-test.py
@@ -10,6 +10,7 @@ from utils import DataLoader, load, save, psnr_error
from constant import const
import evaluate
+from PIL import Image
slim = tf.contrib.slim
@@ -66,6 +67,7 @@ with tf.Session(config=config) as sess:
load(loader, sess, ckpt)
output_records = []
+ outputs = []
videos_info = data_loader.videos
num_videos = len(videos_info.keys())
total = 0
@@ -78,15 +80,19 @@ with tf.Session(config=config) as sess:
for i in range(num_his, length):
video_clip = data_loader.get_video_clips(video_name, i - num_his, i + 1)
- output, psnr = sess.run([test_outputs, test_psnr_error]
+ output, psnr = sess.run([test_outputs, test_psnr_error],
feed_dict={test_video_clips_tensor: video_clip[np.newaxis, ...]})
- outputs[i] = output
+ outputs.append(output)
- tf.image.encode_png(
- output,
- compression=-1,
- name=None
- )
+ #tf.image.encode_png(
+ # output,
+ # compression=-1,
+ # name=None
+ #)
+ ohhh = (output[0,...] + 1.0) * 127.5
+ print(ohhh.shape, np.amin(ohhh), np.amax(ohhh))
+ out = Image.fromarray(ohhh, 'RGB')
+ out.save(os.path.join(os.getcwd(), '{}_{:05d}.png'.format(video_name, i)))
print('video = {} / {}, i = {} / {}, psnr = {:.6f}'.format(
video_name, num_videos, i, length, psnr))
@@ -108,6 +114,7 @@ with tf.Session(config=config) as sess:
# print(results)
+ print(os.path.isdir(snapshot_dir))
if os.path.isdir(snapshot_dir):
def check_ckpt_valid(ckpt_name):
is_valid = False
diff --git a/Codes/test.sh b/Codes/test.sh
new file mode 100644
index 0000000..a683a5a
--- /dev/null
+++ b/Codes/test.sh
@@ -0,0 +1,12 @@
+#python inference-test.py --dataset kaulsdorf_gray \
+# --train_folder /home/lens/Desktop/thumbs/kaulsdorf_gray/Train/ \
+# --test_folder /home/lens/Desktop/thumbs/kaulsdorf_gray/Test/ \
+# --snapshot_dir ./checkpoints/kaulsdorf_gray_l_2_alpha_1_lp_1.0_adv_0.05_gdl_1.0_flow_0.01/model.ckpt-140000 \
+# --gpu 0
+
+python inference-test.py --dataset kaulsdorf_single \
+ --train_folder /home/lens/code/Adversarial_Video_Generation/Data/kaulsdorf_single/Train/ \
+ --test_folder /home/lens/code/Adversarial_Video_Generation/Data/kaulsdorf_single/Test/ \
+ --snapshot_dir ./checkpoints/kaulsdorf_single_l_2_alpha_1_lp_0.001_adv_0.05_gdl_1.0_flow_2.0/model.ckpt-19000 \
+ --gpu 0
+
diff --git a/Codes/train.sh b/Codes/train.sh
new file mode 100644
index 0000000..3145aa9
--- /dev/null
+++ b/Codes/train.sh
@@ -0,0 +1,6 @@
+python train.py --dataset kaulsdorf_gray \
+ --train_folder /home/lens/Desktop/thumbs/kaulsdorf_gray/Train/ \
+ --test_folder /home/lens/Desktop/thumbs/kaulsdorf_gray/Test/ \
+ --gpu 0 \
+ --iters 500000
+
diff --git a/Codes/training_hyper_params/hyper_params.ini b/Codes/training_hyper_params/hyper_params.ini
index f7868f1..963902c 100644
--- a/Codes/training_hyper_params/hyper_params.ini
+++ b/Codes/training_hyper_params/hyper_params.ini
@@ -41,6 +41,52 @@ LRATE_D = [0.00001, 0.000001]
LRATE_D_BOUNDARIES = [40000]
+[kaulsdorf_gray]
+# for lp loss. e.g, 1 or 2 for l1 and l2 loss, respectively)
+L_NUM = 2
+# the power to which each gradient term is raised in GDL loss
+ALPHA_NUM = 1
+# the percentage of the adversarial loss to use in the combined loss
+LAM_ADV = 0.05
+# the percentage of the lp loss to use in the combined loss
+LAM_LP = 1
+# the percentage of the GDL loss to use in the combined loss
+LAM_GDL = 1
+# the percentage of the different frame loss, LAM_FLOW = 2 is also ok, but LAM_FLOW = 0.01 is slightly better.
+LAM_FLOW = 0.01
+
+# For gray scale video, such as Ped2 and Ped1, learning rate of G and D star from 1e-4 and 1e-5, respectively.
+LRATE_G = [0.0001, 0.00001]
+LRATE_G_BOUNDARIES = [40000]
+
+LRATE_D = [0.00001, 0.000001]
+LRATE_D_BOUNDARIES = [40000]
+
+
+[kaulsdorf_single]
+# for lp loss. e.g, 1 or 2 for l1 and l2 loss, respectively)
+L_NUM = 2
+# the power to which each gradient term is raised in GDL loss
+ALPHA_NUM = 1
+# the percentage of the adversarial loss to use in the combined loss
+LAM_ADV = 0.05
+# the percentage of the lp loss to use in the combined loss,
+# we found in smaller lp is slightly better in avenue, but not too much difference
+# LAM_LP = 1 is 84.9, LAM_LP = 0.001 may arrive to 85.1
+LAM_LP = 0.001
+# the percentage of the GDL loss to use in the combined loss
+LAM_GDL = 1
+# the percentage of the different frame loss
+LAM_FLOW = 2
+
+# For rgb color scale video, such as Ped2 and Ped1, learning rate of G and D star from 2e-4 and 2e-5, respectively.
+LRATE_G = [0.0002, 0.00002]
+LRATE_G_BOUNDARIES = [100000]
+
+LRATE_D = [0.00002, 0.000002]
+LRATE_D_BOUNDARIES = [100000]
+
+
[avenue]
# for lp loss. e.g, 1 or 2 for l1 and l2 loss, respectively)
L_NUM = 2
diff --git a/Codes/utils.py b/Codes/utils.py
index 8466d08..7f54fe7 100644
--- a/Codes/utils.py
+++ b/Codes/utils.py
@@ -76,7 +76,7 @@ class DataLoader(object):
video_name = video.split('/')[-1]
self.videos[video_name] = {}
self.videos[video_name]['path'] = video
- self.videos[video_name]['frame'] = glob.glob(os.path.join(video, '*.jpg'))
+ self.videos[video_name]['frame'] = glob.glob(os.path.join(video, '*.png'))
self.videos[video_name]['frame'].sort()
self.videos[video_name]['length'] = len(self.videos[video_name]['frame'])