質問編集履歴
2
URLを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
Githubに公開されているPeeking into the futureの論文のコード(next-prediction)を実行してみたところ,AssertErrorが発生し,エラー文に何も出ておらず,解決への糸口が見つからないため,手助けいただきたいです.
|
6
6
|
|
7
|
+
Github 再現実験手順URL:https://github.com/JunweiLiang/next-prediction/blob/master/code/prepare_data/README.md
|
8
|
+
|
9
|
+
対象のコードURL:https://github.com/JunweiLiang/next-prediction/blob/master/code/prepare_data/step4_generate_traj.py
|
10
|
+
|
7
11
|
|
8
12
|
|
9
13
|
### 発生している問題・エラーメッセージ
|
1
コードが違っていたので,直しました.
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
"""G
|
43
|
+
"""Generate trajectory files and scene, person box, other box, activity files."""
|
44
44
|
|
45
45
|
|
46
46
|
|
@@ -48,17 +48,25 @@
|
|
48
48
|
|
49
49
|
# pylint: disable=g-bad-import-order
|
50
50
|
|
51
|
+
import argparse
|
52
|
+
|
51
53
|
import os
|
52
54
|
|
53
|
-
import
|
55
|
+
import operator
|
54
|
-
|
56
|
+
|
55
|
-
import
|
57
|
+
import numpy as np
|
56
|
-
|
58
|
+
|
57
|
-
|
59
|
+
import cPickle as pickle
|
58
60
|
|
59
61
|
from tqdm import tqdm
|
60
62
|
|
61
|
-
import
|
63
|
+
from glob import glob
|
64
|
+
|
65
|
+
from utils import activity2id
|
66
|
+
|
67
|
+
from utils import actev_scene2imgsize
|
68
|
+
|
69
|
+
from utils import get_scene
|
62
70
|
|
63
71
|
|
64
72
|
|
@@ -66,73 +74,251 @@
|
|
66
74
|
|
67
75
|
parser = argparse.ArgumentParser()
|
68
76
|
|
69
|
-
parser.add_argument("
|
77
|
+
parser.add_argument("npzpath")
|
70
|
-
|
78
|
+
|
71
|
-
parser.add_argument("
|
79
|
+
parser.add_argument("split_path")
|
72
80
|
|
73
81
|
parser.add_argument("out_path")
|
74
82
|
|
75
|
-
parser.add_argument("--
|
76
|
-
|
77
|
-
help="
|
78
|
-
|
79
|
-
" r
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
parser.add_argument("--
|
86
|
-
|
87
|
-
help="get
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
parser.add_argument("--
|
102
|
-
|
103
|
-
help="
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
w
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
i
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
new
|
134
|
-
|
135
|
-
|
83
|
+
parser.add_argument("--drop_frame", default=1, type=int,
|
84
|
+
|
85
|
+
help="drop frame to match different fps, assuming "
|
86
|
+
|
87
|
+
"the virat fps is 30fps, so to get 2.5fps, "
|
88
|
+
|
89
|
+
"need to drop 12 frames every time")
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
parser.add_argument("--scene_feat_path",
|
94
|
+
|
95
|
+
help="the scene segmentation output path,"
|
96
|
+
|
97
|
+
"under it should be frame_name.npy")
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# the following are the output paths
|
102
|
+
|
103
|
+
parser.add_argument("--scene_map_path",
|
104
|
+
|
105
|
+
help="frameidx mapping to actual scene feature file output")
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
parser.add_argument("--person_box_path",
|
110
|
+
|
111
|
+
help="Person box output")
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
parser.add_argument("--other_box_path",
|
116
|
+
|
117
|
+
help="Other object box output")
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
parser.add_argument("--activity_path",
|
122
|
+
|
123
|
+
help="activity annotation output")
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# for ETH/UCY you need to write your own video size mapping
|
128
|
+
|
129
|
+
# In the PeekingFuture paper we resize ETH/UCY to 720x576 to extract features
|
130
|
+
|
131
|
+
scene2imgsize = actev_scene2imgsize
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
actid2name = {activity2id[n]: n for n in activity2id}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def resize_xy(xy, vname, resize_w, resize_h):
|
142
|
+
|
143
|
+
"""Resize the xy coordinates."""
|
144
|
+
|
145
|
+
x_, y_ = xy
|
146
|
+
|
147
|
+
w, h = scene2imgsize[get_scene(vname)]
|
148
|
+
|
149
|
+
diff_w = resize_w / float(w)
|
150
|
+
|
151
|
+
diff_h = resize_h / float(h)
|
152
|
+
|
153
|
+
x_ *= diff_w
|
154
|
+
|
155
|
+
y_ *= diff_h
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
# normalize coordinates?
|
160
|
+
|
161
|
+
return [x_, y_]
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
def resize_box(box, vname, resize_w, resize_h):
|
168
|
+
|
169
|
+
"""Resize the box coordintates."""
|
170
|
+
|
171
|
+
x1, y1, x2, y2 = [float(o) for o in box]
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
w, h = scene2imgsize[get_scene(vname)]
|
176
|
+
|
177
|
+
diff_w = resize_w / float(w)
|
178
|
+
|
179
|
+
diff_h = resize_h / float(h)
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
x1 *= diff_w
|
184
|
+
|
185
|
+
x2 *= diff_w
|
186
|
+
|
187
|
+
y1 *= diff_h
|
188
|
+
|
189
|
+
y2 *= diff_h
|
190
|
+
|
191
|
+
return [x1, y1, x2, y2]
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
# frame_lst is [(videoname,frameidx)], assume sorted by the frameidx
|
198
|
+
|
199
|
+
def get_nearest(frame_lst_, frame_idx):
|
200
|
+
|
201
|
+
"""Since we don't run scene seg on every frame, we want to find the nearest one."""
|
202
|
+
|
203
|
+
frame_idxs = np.array([i_ for _, i_ in frame_lst_])
|
204
|
+
|
205
|
+
cloests_idx = (np.abs(frame_idxs - frame_idx)).argmin()
|
206
|
+
|
207
|
+
vname, closest_frame_idx = frame_lst_[cloests_idx]
|
208
|
+
|
209
|
+
return vname, closest_frame_idx, cloests_idx
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
def get_act_list(act_data, frameidx, bgid):
|
216
|
+
|
217
|
+
"""Given a frameidx, get this person' activities."""
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
# act_data is a list of sorted (start,end,actclassid)
|
222
|
+
|
223
|
+
# return current act list,
|
224
|
+
|
225
|
+
current_act_list = [(actid, e - frameidx) for s, e, actid in act_data
|
226
|
+
|
227
|
+
if (frameidx >= s) and (frameidx <= e)]
|
228
|
+
|
229
|
+
current_act_list.sort(key=operator.itemgetter(1)) # dist to current act's end
|
230
|
+
|
231
|
+
current_actid_list_ = [actid for actid, _ in current_act_list]
|
232
|
+
|
233
|
+
current_dist_list_ = [dist for _, dist in current_act_list]
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
if not current_act_list:
|
238
|
+
|
239
|
+
current_actid_list_, current_dist_list_ = [bgid], [-1]
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
future_act_list = [(actid, s - frameidx) for s, e, actid in act_data
|
244
|
+
|
245
|
+
if frameidx < s]
|
246
|
+
|
247
|
+
future_act_list.sort(key=operator.itemgetter(1))
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
if not future_act_list:
|
252
|
+
|
253
|
+
return (current_actid_list_, current_dist_list_, [bgid], [-1])
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
# only the nearest future activity?
|
258
|
+
|
259
|
+
# smallest_dist = future_act_list[0][1]
|
260
|
+
|
261
|
+
# future_act_list = [(actid,dist) for actid, dist in future_act_list
|
262
|
+
|
263
|
+
# if dist == smallest_dist]
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
future_actid_list_ = [actid for actid, _ in future_act_list]
|
268
|
+
|
269
|
+
future_dist_list_ = [dist for _, dist in future_act_list]
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
return (current_actid_list_, current_dist_list_,
|
274
|
+
|
275
|
+
future_actid_list_, future_dist_list_)
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
def check_traj(newdata_, vname):
|
282
|
+
|
283
|
+
"""Check and filter data."""
|
284
|
+
|
285
|
+
checkdata = np.array(newdata_, dtype="float")
|
286
|
+
|
287
|
+
frames_ = np.unique(checkdata[:, 0]).tolist()
|
288
|
+
|
289
|
+
checked_data_ = []
|
290
|
+
|
291
|
+
for frame_ in frames_:
|
292
|
+
|
293
|
+
# all personid in this frame
|
294
|
+
|
295
|
+
this_frame_data = checkdata[frame_ == checkdata[:, 0], :] # [K,4]
|
296
|
+
|
297
|
+
ped_ids = this_frame_data[:, 1]
|
298
|
+
|
299
|
+
unique_ped_ids, unique_idxs = np.unique(ped_ids, return_index=True)
|
300
|
+
|
301
|
+
if len(ped_ids) != len(unique_ped_ids):
|
302
|
+
|
303
|
+
tqdm.write("\twarning, %s frame %s has duplicate person annotation person"
|
304
|
+
|
305
|
+
" ids: %s/%s, removed the duplicate ones"
|
306
|
+
|
307
|
+
% (vname, frame_, len(unique_ped_ids), len(ped_ids)))
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
this_frame_data = this_frame_data[unique_idxs]
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
for f_, p_, x_, y_ in this_frame_data:
|
316
|
+
|
317
|
+
checked_data_.append((f_, p_, x_, y_))
|
318
|
+
|
319
|
+
checked_data_.sort(key=operator.itemgetter(0))
|
320
|
+
|
321
|
+
return checked_data_
|
136
322
|
|
137
323
|
|
138
324
|
|
@@ -144,133 +330,121 @@
|
|
144
330
|
|
145
331
|
|
146
332
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
gr
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
t
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
(
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
...
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
"""
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
seg_map = resize_seg_map(seg_map, args.down_rate, args.keep_full)
|
268
|
-
|
269
|
-
targetfile = os.path.join(args.out_path, "%s.npy" % imgname)
|
270
|
-
|
271
|
-
np.save(targetfile, seg_map)
|
272
|
-
|
273
|
-
|
333
|
+
# Hard coded for ActEV experiment.
|
334
|
+
|
335
|
+
# :P
|
336
|
+
|
337
|
+
args.resize = True
|
338
|
+
|
339
|
+
args.resize_h = 1080
|
340
|
+
|
341
|
+
args.resize_w = 1920
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
filelst = {
|
346
|
+
|
347
|
+
"train": [os.path.splitext(os.path.basename(line.strip()))[0]
|
348
|
+
|
349
|
+
for line in open(os.path.join(args.split_path,
|
350
|
+
|
351
|
+
"train.lst"), "r").readlines()],
|
352
|
+
|
353
|
+
"val": [os.path.splitext(os.path.basename(line.strip()))[0]
|
354
|
+
|
355
|
+
for line in open(os.path.join(args.split_path,
|
356
|
+
|
357
|
+
"val.lst"), "r").readlines()],
|
358
|
+
|
359
|
+
"test": [os.path.splitext(os.path.basename(line.strip()))[0]
|
360
|
+
|
361
|
+
for line in open(os.path.join(args.split_path,
|
362
|
+
|
363
|
+
"test.lst"), "r").readlines()],
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
for split in tqdm(filelst, ascii=True):
|
370
|
+
|
371
|
+
out_path = os.path.join(args.out_path, split)
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
if not os.path.exists(out_path):
|
376
|
+
|
377
|
+
os.makedirs(out_path)
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
if not os.path.exists(os.path.join(args.person_box_path, split)):
|
382
|
+
|
383
|
+
os.makedirs(os.path.join(args.person_box_path, split))
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
if not os.path.exists(os.path.join(args.other_box_path, split)):
|
388
|
+
|
389
|
+
os.makedirs(os.path.join(args.other_box_path, split))
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
if not os.path.exists(os.path.join(args.activity_path, split)):
|
394
|
+
|
395
|
+
os.makedirs(os.path.join(args.activity_path, split))
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
scene_map_path = os.path.join(args.scene_map_path, split)
|
400
|
+
|
401
|
+
if not os.path.exists(scene_map_path):
|
402
|
+
|
403
|
+
os.makedirs(scene_map_path)
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
for videoname in tqdm(filelst[split]):
|
408
|
+
|
409
|
+
npzfile = os.path.join(args.npzpath, "%s.npz" % videoname)
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
data = np.load(npzfile, allow_pickle=True)
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
# each frame's all boxes, for getting other boxes
|
418
|
+
|
419
|
+
frameidx2boxes = data["frameidx2boxes"]
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
# personId -> all related activity with timespan, sorted by timespan start
|
424
|
+
|
425
|
+
# (start, end, act_classid)
|
426
|
+
|
427
|
+
personid2acts = data["personid2acts"]
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
# load all the frames for this video first
|
432
|
+
|
433
|
+
frame_lst = glob(os.path.join(args.scene_feat_path,
|
434
|
+
|
435
|
+
"%s_F_*.npy"%videoname))
|
436
|
+
|
437
|
+
assert frame_lst
|
438
|
+
|
439
|
+
frame_lst = [(os.path.basename(frame),
|
440
|
+
|
441
|
+
int(os.path.basename(frame).split(".")[0].split("_F_")[-1]))
|
442
|
+
|
443
|
+
for frame in frame_lst]
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
・・・
|
274
448
|
|
275
449
|
```
|
276
450
|
|