Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Commit 651696b

Browse files
committed
linted codes. Now it is readable.
1 parent 9b4b830 commit 651696b

9 files changed

+4389
-4080
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ If you find this code useful in your research then please cite
1313
year={2019},
1414
organization={IEEE}
1515
}
16-
@article{changmmvg,
17-
title={MMVG-INF-Etrol@ TRECVID 2019: Activities in Extended Video},
18-
author={Chang, Xiaojun and Liu, Wenhe and Huang, Po-Yao and Li, Changlin and Zhu, Fengda and Han, Mingfei and Li, Mingjie and Ma, Mengyuan and Hu, Siyi and Kang, Guoliang and others}
19-
booktitle={TRECVID 2019 Workshop. Gaithersburg, MD, USA},
20-
year={2019}
16+
@inproceedings{liu2020wacv,
17+
author = {Liu, Wenhe and Kang, Guoliang and Huang, Po-Yao and Chang, Xiaojun and Qian, Yijun and Liang, Junwei and Gui, Liangke and Wen, Jing and Chen, Peng},
18+
title = {Argus: Efficient Activity Detection System for Extended Video Analysis},
19+
booktitle = {The IEEE Winter Conference on Applications of Computer Vision (WACV) Workshops},
20+
month = {March},
21+
year = {2020}
2122
}
2223
```
2324

@@ -44,12 +45,14 @@ The code is originally written for Tensorflow v1.10 with Python 2/3 but it works
4445
Other dependencies: numpy; scipy; sklearn; cv2; matplotlib; pycocotools
4546

4647
## Code Overview
47-
- `obj_detect.py`: Inference code for object detection.
4848
- `obj_detect_tracking.py`: Inference code for object detection & tracking.
4949
- `models.py`: Main model definition.
5050
- `nn.py`: Some layer definitions.
5151
- `main.py`: Code I used for training and testing experiments.
52-
52+
- `eval.py`: Code I used for getting mAP/mAR.
53+
- `vis_json.py`: visualize the json outputs.
54+
- `get_frames_resize.py`: code for extracting frames from videos.
55+
- `utils.py`: some helper classes like getting moving average of losses and GPU usage.
5356

5457
## Inferencing
5558
1. First download some test videos and the v3 model (v4-v6 models are un-verified models as we don't have a test set with ground truth):

get_frames_resize.py

+58-46
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
# coding=utf-8
2-
# given a list of videos, get all the frames and resize
3-
# note that the frames are 0-indexed
2+
"""
3+
given a list of videos, get all the frames and resize note that the
4+
frames are 0-indexed
5+
"""
6+
7+
import argparse
8+
import cv2
9+
import os
10+
import pickle
11+
import sys
412

5-
import sys,os,argparse
613
from tqdm import tqdm
7-
import cPickle as pickle
814

9-
def get_args():
10-
parser = argparse.ArgumentParser()
15+
parser = argparse.ArgumentParser()
16+
17+
parser.add_argument("videolist")
18+
parser.add_argument("despath")
1119

12-
parser.add_argument("videolist")
13-
parser.add_argument("despath")
20+
parser.add_argument("--resize", default=False, action="store_true")
21+
parser.add_argument("--size", default=800, type=int)
22+
parser.add_argument("--maxsize", default=1333, type=int)
1423

15-
parser.add_argument("--size",default=800,type=int)
16-
parser.add_argument("--maxsize",default=1333,type=int)
1724

18-
parser.add_argument("--resize",default=False,action="store_true")
1925

20-
parser.add_argument("--job",type=int,default=1,help="total job")
21-
parser.add_argument("--curJob",type=int,default=1,help="this script run job Num")
22-
parser.add_argument("--statspath",default=None,help="path to write videoname.p to save some stats for that video")
23-
parser.add_argument("--use_2level",action="store_true",help="make videoname/frames dir")
24-
parser.add_argument("--name_level",type=int,default=None,help="add the top level folder name to the videoname")
25-
parser.add_argument("--cv2path",default=None)
26+
parser.add_argument("--job", type=int, default=1, help="total job")
27+
parser.add_argument("--curJob", type=int, default=1,
28+
help="this script run job Num")
29+
parser.add_argument("--statspath", default=None,
30+
help="path to write videoname.p to save some stats for "
31+
"that video")
32+
parser.add_argument("--use_2level", action="store_true",
33+
help="make videoname/frames dir")
34+
parser.add_argument("--name_level", type=int, default=None,
35+
help="add the top level folder name to the videoname")
36+
parser.add_argument("--cv2path", default=None)
2637

27-
parser.add_argument("--use_moviepy", action="store_true")
28-
parser.add_argument("--use_lijun", action="store_true")
38+
parser.add_argument("--use_moviepy", action="store_true")
39+
parser.add_argument("--use_lijun", action="store_true")
2940

30-
return parser.parse_args()
3141

32-
def get_new_hw(h,w,size,max_size):
42+
def get_new_hw(h, w, size, max_size):
43+
"""Get new hw."""
3344
scale = size * 1.0 / min(h, w)
3445
if h < w:
3546
newh, neww = size, scale * w
@@ -41,46 +52,45 @@ def get_new_hw(h,w,size,max_size):
4152
neww = neww * scale
4253
neww = int(neww + 0.5)
4354
newh = int(newh + 0.5)
44-
return neww,newh
55+
return neww, newh
4556

4657

4758
if __name__ == "__main__":
48-
args = get_args()
59+
args = parser.parse_args()
4960
if args.cv2path is not None:
5061
sys.path = [args.cv2path] + sys.path
5162

52-
5363
if args.use_moviepy:
5464
from moviepy.editor import VideoFileClip
5565
elif args.use_lijun:
5666
from diva_io.video import VideoReader
5767

5868
# still need this to write image
59-
import cv2
60-
print "using opencv version:%s"%(cv2.__version__)
69+
print("using opencv version:%s"%(cv2.__version__))
6170

6271
if not os.path.exists(args.despath):
6372
os.makedirs(args.despath)
6473

6574
if args.statspath is not None and not os.path.exists(args.statspath):
6675
os.makedirs(args.statspath)
6776

68-
count=0
69-
for line in tqdm(open(args.videolist,"r").readlines()):
70-
count+=1
71-
if((count % args.job) != (args.curJob-1)):
77+
count = 0
78+
for line in tqdm(open(args.videolist, "r").readlines()):
79+
count += 1
80+
if (count % args.job) != (args.curJob-1):
7281
continue
7382

7483
video = line.strip()
7584

76-
stats = {"h":None,"w":None,"fps":None,"frame_count":None,"actual_frame_count":None}
85+
stats = {"h":None, "w":None, "fps":None, "frame_count":None,
86+
"actual_frame_count":None}
7787

7888
videoname = os.path.splitext(os.path.basename(video))[0]
7989

8090
targetpath = args.despath
8191

8292
if args.use_2level:
83-
targetpath = os.path.join(args.despath,videoname)
93+
targetpath = os.path.join(args.despath, videoname)
8494
if not os.path.exists(targetpath):
8595
os.makedirs(targetpath)
8696

@@ -125,8 +135,8 @@ def get_new_hw(h,w,size,max_size):
125135

126136
stats['frame_count'] = frame_count
127137

128-
cur_frame=0
129-
count_actual=0
138+
cur_frame = 0
139+
count_actual = 0
130140
while cur_frame < frame_count:
131141
if args.use_moviepy:
132142
suc = True
@@ -136,29 +146,31 @@ def get_new_hw(h,w,size,max_size):
136146
suc, frame = vcap.read()
137147

138148
if not suc:
139-
cur_frame+=1
140-
tqdm.write("warning, %s frame of %s failed"%(cur_frame,videoname))
149+
cur_frame += 1
150+
tqdm.write("warning, %s frame of %s failed" % (cur_frame, videoname))
141151
continue
142-
count_actual+=1
152+
count_actual += 1
143153
if args.use_moviepy:
144-
# moviepy ask ffmpeg to get rgb24
145-
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
154+
# moviepy ask ffmpeg to get rgb24
155+
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
156+
146157
frame = frame.astype("float32")
147158

148159
if args.resize:
149-
neww,newh = get_new_hw(frame.shape[0],frame.shape[1],args.size,args.maxsize)
160+
neww, newh = get_new_hw(frame.shape[0],
161+
frame.shape[1], args.size, args.maxsize)
150162

151-
frame = cv2.resize(frame,(neww,newh),interpolation=cv2.INTER_LINEAR)
163+
frame = cv2.resize(frame, (neww, newh), interpolation=cv2.INTER_LINEAR)
152164

153-
cv2.imwrite(os.path.join(targetpath,"%s_F_%08d.jpg"%(videoname,cur_frame)),frame)
165+
cv2.imwrite(os.path.join(targetpath,
166+
"%s_F_%08d.jpg" % (videoname, cur_frame)), frame)
154167

155-
cur_frame+=1
168+
cur_frame += 1
156169

157170
stats['actual_frame_count'] = count_actual
158171

159172
if args.statspath is not None:
160-
with open(os.path.join(args.statspath,"%s.p"%videoname),"wb") as fs:
161-
pickle.dump(stats,fs)
173+
with open(os.path.join(args.statspath, "%s.p" % videoname), "wb") as fs:
174+
pickle.dump(stats, fs)
162175
if not args.use_moviepy and not args.use_lijun:
163176
vcap.release()
164-

0 commit comments

Comments
 (0)