Update dataset.py
Browse files- dataset.py +115 -115
dataset.py
CHANGED
|
@@ -97,7 +97,7 @@ class VideoDataSet(data.Dataset):
|
|
| 97 |
self.feature_rgb_file = {}
|
| 98 |
self.feature_flow_file = {}
|
| 99 |
for file in self.video_list:
|
| 100 |
-
feature_path = opt["video_feature_all_train"]
|
| 101 |
if not os.path.exists(feature_path):
|
| 102 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 103 |
feature_All[file] = np.load(feature_path)['feats']
|
|
@@ -110,7 +110,7 @@ class VideoDataSet(data.Dataset):
|
|
| 110 |
self.feature_rgb_file = {}
|
| 111 |
self.feature_flow_file = {}
|
| 112 |
for file in self.video_list:
|
| 113 |
-
feature_path = opt["video_feature_all_train"]
|
| 114 |
if not os.path.exists(feature_path):
|
| 115 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 116 |
feature_All[file] = np.load(feature_path)
|
|
@@ -123,7 +123,7 @@ class VideoDataSet(data.Dataset):
|
|
| 123 |
self.feature_rgb_file = {}
|
| 124 |
self.feature_flow_file = {}
|
| 125 |
for file in self.video_list:
|
| 126 |
-
feature_path = opt["video_feature_all_train"]
|
| 127 |
if not os.path.exists(feature_path):
|
| 128 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 129 |
feature_All[file] = torch.load(feature_path)
|
|
@@ -164,7 +164,7 @@ class VideoDataSet(data.Dataset):
|
|
| 164 |
self.feature_rgb_file = {}
|
| 165 |
self.feature_flow_file = {}
|
| 166 |
for file in self.video_list:
|
| 167 |
-
feature_path = opt[
|
| 168 |
if not os.path.exists(feature_path):
|
| 169 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 170 |
feature_All[file] = np.load(feature_path)['feats']
|
|
@@ -177,7 +177,7 @@ class VideoDataSet(data.Dataset):
|
|
| 177 |
self.feature_rgb_file = {}
|
| 178 |
self.feature_flow_file = {}
|
| 179 |
for file in self.video_list:
|
| 180 |
-
feature_path = opt[
|
| 181 |
if not os.path.exists(feature_path):
|
| 182 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 183 |
feature_All[file] = np.load(feature_path)
|
|
@@ -190,7 +190,7 @@ class VideoDataSet(data.Dataset):
|
|
| 190 |
self.feature_rgb_file = {}
|
| 191 |
self.feature_flow_file = {}
|
| 192 |
for file in self.video_list:
|
| 193 |
-
feature_path = opt[
|
| 194 |
if not os.path.exists(feature_path):
|
| 195 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 196 |
feature_All[file] = torch.load(feature_path)
|
|
@@ -213,7 +213,7 @@ class VideoDataSet(data.Dataset):
|
|
| 213 |
elif opt['data_format'] == "npz":
|
| 214 |
feature_file = {}
|
| 215 |
for file in self.video_list:
|
| 216 |
-
feature_path = opt["video_feature_all_train"]
|
| 217 |
if os.path.exists(feature_path):
|
| 218 |
feature_file[file] = np.load(feature_path)['feats']
|
| 219 |
else:
|
|
@@ -221,7 +221,7 @@ class VideoDataSet(data.Dataset):
|
|
| 221 |
elif opt['data_format'] == "npz_i3d":
|
| 222 |
feature_file = {}
|
| 223 |
for file in self.video_list:
|
| 224 |
-
feature_path = opt["video_feature_all_train"]
|
| 225 |
if os.path.exists(feature_path):
|
| 226 |
feature_file[file] = np.load(feature_path)
|
| 227 |
else:
|
|
@@ -229,7 +229,7 @@ class VideoDataSet(data.Dataset):
|
|
| 229 |
elif opt['data_format'] == "pt":
|
| 230 |
feature_file = {}
|
| 231 |
for file in self.video_list:
|
| 232 |
-
feature_path = opt["video_feature_all_train"]
|
| 233 |
if os.path.exists(feature_path):
|
| 234 |
feature_file[file] = torch.load(feature_path)
|
| 235 |
else:
|
|
@@ -242,7 +242,7 @@ class VideoDataSet(data.Dataset):
|
|
| 242 |
elif opt['data_format'] == "npz":
|
| 243 |
feature_file = {}
|
| 244 |
for file in self.video_list:
|
| 245 |
-
feature_path = opt[
|
| 246 |
if os.path.exists(feature_path):
|
| 247 |
feature_file[file] = np.load(feature_path)['feats']
|
| 248 |
else:
|
|
@@ -250,7 +250,7 @@ class VideoDataSet(data.Dataset):
|
|
| 250 |
elif opt['data_format'] == "npz_i3d":
|
| 251 |
feature_file = {}
|
| 252 |
for file in self.video_list:
|
| 253 |
-
feature_path = opt[
|
| 254 |
if os.path.exists(feature_path):
|
| 255 |
feature_file[file] = np.load(feature_path)
|
| 256 |
else:
|
|
@@ -258,7 +258,7 @@ class VideoDataSet(data.Dataset):
|
|
| 258 |
elif opt['data_format'] == "pt":
|
| 259 |
feature_file = {}
|
| 260 |
for file in self.video_list:
|
| 261 |
-
feature_path = opt[
|
| 262 |
if os.path.exists(feature_path):
|
| 263 |
feature_file[file] = torch.load(feature_path)
|
| 264 |
else:
|
|
@@ -368,29 +368,29 @@ class VideoDataSet(data.Dataset):
|
|
| 368 |
video_name = self.video_list[index]
|
| 369 |
duration = self.match_score[video_name].shape[0]
|
| 370 |
for i in range(1, duration + 1):
|
| 371 |
-
st = i - self.
|
| 372 |
ed = i
|
| 373 |
-
self.
|
| 374 |
data_idx += 1
|
| 375 |
|
| 376 |
-
self.
|
| 377 |
-
print(f"{self.
|
| 378 |
|
| 379 |
def _makePropLabelUnit(self, i):
|
| 380 |
-
video_name = self.
|
| 381 |
-
st = self.
|
| 382 |
-
ed = self.
|
| 383 |
cls_anc = []
|
| 384 |
reg_anc = []
|
| 385 |
|
| 386 |
-
for j in range(0, len(self.
|
| 387 |
-
v1 = np.zeros(self.
|
| 388 |
v1[-1] = 1
|
| 389 |
v2 = np.zeros(2)
|
| 390 |
v2[-1] = -1e3
|
| 391 |
-
y_box = [ed - 1, self.
|
| 392 |
|
| 393 |
-
subset_label = self.
|
| 394 |
idx_list = []
|
| 395 |
for ii in range(0, subset_label.shape[0]):
|
| 396 |
for jj in range(0, subset_label.shape[1]):
|
|
@@ -399,23 +399,23 @@ class VideoDataSet(data.Dataset):
|
|
| 399 |
idx_list.append(idx - 1)
|
| 400 |
|
| 401 |
for idx in idx_list:
|
| 402 |
-
|
| 403 |
-
cls = int(
|
| 404 |
-
iou = calc_iou(
|
| 405 |
-
if iou >= self.
|
| 406 |
v1[cls] = 1
|
| 407 |
v1[-1] = 0
|
| 408 |
-
v2[0] = 1.0 * (target_box[0] - y_box[0]) / self.
|
| 409 |
v2[1] = np.log(1.0 * max(1, target_box[1]) / y_box[1])
|
| 410 |
|
| 411 |
cls_anc.append(v1)
|
| 412 |
reg_anc.append(v2)
|
| 413 |
|
| 414 |
-
v0 = np.zeros(self.
|
| 415 |
v0[-1] = 1
|
| 416 |
segment_size = ed - st
|
| 417 |
-
y_box = [ed - 1, self.
|
| 418 |
-
subset_label = self.
|
| 419 |
idx_list = []
|
| 420 |
for ii in range(0, subset_label.shape[0]):
|
| 421 |
for jj in range(0, subset_label.shape[1]):
|
|
@@ -424,141 +424,141 @@ class VideoDataSet(data.Dataset):
|
|
| 424 |
idx_list.append(idx - 1)
|
| 425 |
|
| 426 |
for idx in idx_list:
|
| 427 |
-
target_box = self.
|
| 428 |
cls = int(target_box[2])
|
| 429 |
iou = calc_iou(y_box, target_box)
|
| 430 |
if iou >= 0:
|
| 431 |
v0[cls] = 1
|
| 432 |
v0[-1] = 0
|
| 433 |
|
| 434 |
-
cls_anc = np.stack(
|
| 435 |
-
reg_anc = np.stack(
|
| 436 |
cls_snip = np.array(v0)
|
| 437 |
return cls_anc, reg_anc, cls_snip
|
| 438 |
|
| 439 |
def _loadPropLabel(self, filename):
|
| 440 |
if os.path.exists(filename):
|
| 441 |
prop_label_file = h5py.File(filename, 'r')
|
| 442 |
-
self.
|
| 443 |
-
self.
|
| 444 |
-
self.
|
| 445 |
prop_label_file.close()
|
| 446 |
-
self.
|
| 447 |
-
self.
|
| 448 |
return
|
| 449 |
|
| 450 |
pool = Pool(os.cpu_count() // 2)
|
| 451 |
-
labels = pool.map(self._makePropLabelUnit, range(0, len(self.
|
| 452 |
pool.close()
|
| 453 |
-
pool.join()
|
| 454 |
|
| 455 |
cls_label = []
|
| 456 |
reg_label = []
|
| 457 |
snip_label = []
|
| 458 |
for i in range(0, len(labels)):
|
| 459 |
-
cls_label.append(labels[i][0])
|
| 460 |
reg_label.append(labels[i][1])
|
| 461 |
snip_label.append(labels[i][2])
|
| 462 |
-
self.
|
| 463 |
-
self.
|
| 464 |
-
self.
|
| 465 |
|
| 466 |
outfile = h5py.File(filename, 'w')
|
| 467 |
-
dset_cls = outfile.
|
| 468 |
-
dset_cls[
|
| 469 |
-
|
| 470 |
-
dset_reg[
|
| 471 |
-
|
| 472 |
-
dset_snip[
|
| 473 |
-
outfile.
|
| 474 |
|
| 475 |
return
|
| 476 |
|
| 477 |
-
def
|
| 478 |
-
video_name, st, ed,
|
| 479 |
if st >= 0:
|
| 480 |
-
|
| 481 |
else:
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
|
| 490 |
-
return
|
| 491 |
|
| 492 |
def _get_base_data(self, video_name, st, ed):
|
| 493 |
-
|
| 494 |
-
|
| 495 |
|
| 496 |
-
if self.
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
else:
|
| 501 |
-
|
| 502 |
-
|
| 503 |
|
| 504 |
-
return
|
| 505 |
|
| 506 |
-
def _get_train_label_with_class(self, video_name, st,
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
if st < 0:
|
| 511 |
-
|
| 512 |
-
st =
|
| 513 |
-
if
|
| 514 |
-
|
| 515 |
-
|
| 516 |
|
| 517 |
-
|
| 518 |
-
if
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
if
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
return
|
| 525 |
|
| 526 |
-
def
|
| 527 |
-
return len(self.
|
| 528 |
|
| 529 |
-
def
|
| 530 |
-
self.
|
| 531 |
|
| 532 |
-
def
|
| 533 |
-
|
| 534 |
-
self.
|
| 535 |
return
|
| 536 |
|
| 537 |
class SuppressDataSet(data.Dataset):
|
| 538 |
def __init__(self, opt, subset="train"):
|
| 539 |
-
self.
|
| 540 |
-
self.
|
| 541 |
-
self.
|
| 542 |
-
self.
|
| 543 |
-
self.
|
| 544 |
-
for
|
| 545 |
-
video_name = self.
|
| 546 |
-
|
| 547 |
-
for i in range(0,
|
| 548 |
-
self.
|
| 549 |
|
| 550 |
-
print(f"{self.
|
| 551 |
|
| 552 |
-
def
|
| 553 |
-
video_name, idx = self.
|
| 554 |
|
| 555 |
-
|
| 556 |
-
|
| 557 |
|
| 558 |
-
|
| 559 |
-
|
| 560 |
|
| 561 |
-
return
|
| 562 |
|
| 563 |
-
def
|
| 564 |
-
return len(self.
|
|
|
|
| 97 |
self.feature_rgb_file = {}
|
| 98 |
self.feature_flow_file = {}
|
| 99 |
for file in self.video_list:
|
| 100 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.npz')
|
| 101 |
if not os.path.exists(feature_path):
|
| 102 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 103 |
feature_All[file] = np.load(feature_path)['feats']
|
|
|
|
| 110 |
self.feature_rgb_file = {}
|
| 111 |
self.feature_flow_file = {}
|
| 112 |
for file in self.video_list:
|
| 113 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.npz')
|
| 114 |
if not os.path.exists(feature_path):
|
| 115 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 116 |
feature_All[file] = np.load(feature_path)
|
|
|
|
| 123 |
self.feature_rgb_file = {}
|
| 124 |
self.feature_flow_file = {}
|
| 125 |
for file in self.video_list:
|
| 126 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.pt')
|
| 127 |
if not os.path.exists(feature_path):
|
| 128 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 129 |
feature_All[file] = torch.load(feature_path)
|
|
|
|
| 164 |
self.feature_rgb_file = {}
|
| 165 |
self.feature_flow_file = {}
|
| 166 |
for file in self.video_list:
|
| 167 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.npz')
|
| 168 |
if not os.path.exists(feature_path):
|
| 169 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 170 |
feature_All[file] = np.load(feature_path)['feats']
|
|
|
|
| 177 |
self.feature_rgb_file = {}
|
| 178 |
self.feature_flow_file = {}
|
| 179 |
for file in self.video_list:
|
| 180 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.npz')
|
| 181 |
if not os.path.exists(feature_path):
|
| 182 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 183 |
feature_All[file] = np.load(feature_path)
|
|
|
|
| 190 |
self.feature_rgb_file = {}
|
| 191 |
self.feature_flow_file = {}
|
| 192 |
for file in self.video_list:
|
| 193 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.pt')
|
| 194 |
if not os.path.exists(feature_path):
|
| 195 |
raise ValueError(f"Feature file {feature_path} not found")
|
| 196 |
feature_All[file] = torch.load(feature_path)
|
|
|
|
| 213 |
elif opt['data_format'] == "npz":
|
| 214 |
feature_file = {}
|
| 215 |
for file in self.video_list:
|
| 216 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.npz')
|
| 217 |
if os.path.exists(feature_path):
|
| 218 |
feature_file[file] = np.load(feature_path)['feats']
|
| 219 |
else:
|
|
|
|
| 221 |
elif opt['data_format'] == "npz_i3d":
|
| 222 |
feature_file = {}
|
| 223 |
for file in self.video_list:
|
| 224 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.npz')
|
| 225 |
if os.path.exists(feature_path):
|
| 226 |
feature_file[file] = np.load(feature_path)
|
| 227 |
else:
|
|
|
|
| 229 |
elif opt['data_format'] == "pt":
|
| 230 |
feature_file = {}
|
| 231 |
for file in self.video_list:
|
| 232 |
+
feature_path = os.path.join(opt["video_feature_all_train"], file + '.pt')
|
| 233 |
if os.path.exists(feature_path):
|
| 234 |
feature_file[file] = torch.load(feature_path)
|
| 235 |
else:
|
|
|
|
| 242 |
elif opt['data_format'] == "npz":
|
| 243 |
feature_file = {}
|
| 244 |
for file in self.video_list:
|
| 245 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.npz')
|
| 246 |
if os.path.exists(feature_path):
|
| 247 |
feature_file[file] = np.load(feature_path)['feats']
|
| 248 |
else:
|
|
|
|
| 250 |
elif opt['data_format'] == "npz_i3d":
|
| 251 |
feature_file = {}
|
| 252 |
for file in self.video_list:
|
| 253 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.npz')
|
| 254 |
if os.path.exists(feature_path):
|
| 255 |
feature_file[file] = np.load(feature_path)
|
| 256 |
else:
|
|
|
|
| 258 |
elif opt['data_format'] == "pt":
|
| 259 |
feature_file = {}
|
| 260 |
for file in self.video_list:
|
| 261 |
+
feature_path = os.path.join(opt['video_feature_all_test'], file + '.pt')
|
| 262 |
if os.path.exists(feature_path):
|
| 263 |
feature_file[file] = torch.load(feature_path)
|
| 264 |
else:
|
|
|
|
| 368 |
video_name = self.video_list[index]
|
| 369 |
duration = self.match_score[video_name].shape[0]
|
| 370 |
for i in range(1, duration + 1):
|
| 371 |
+
st = i - self._segment_size
|
| 372 |
ed = i
|
| 373 |
+
self._inputs_all.append([video_name, st, ed, data_idx])
|
| 374 |
data_idx += 1
|
| 375 |
|
| 376 |
+
self._inputs = self._inputs_all.copy()
|
| 377 |
+
print(f"{self._subset} subset seg numbers: {len(self._inputs)}")
|
| 378 |
|
| 379 |
def _makePropLabelUnit(self, i):
|
| 380 |
+
video_name = self._inputs_all[i][0]
|
| 381 |
+
st = self._inputs_all[i][1]
|
| 382 |
+
ed = self._inputs_all[i][2]
|
| 383 |
cls_anc = []
|
| 384 |
reg_anc = []
|
| 385 |
|
| 386 |
+
for j in range(0, len(self._anchors)):
|
| 387 |
+
v1 = np.zeros(self._num_of_class)
|
| 388 |
v1[-1] = 1
|
| 389 |
v2 = np.zeros(2)
|
| 390 |
v2[-1] = -1e3
|
| 391 |
+
y_box = [ed - 1, self._anchors[j]]
|
| 392 |
|
| 393 |
+
subset_label = self._get_train_subset_label(video_name, ed - self._anchors[j], ed)
|
| 394 |
idx_list = []
|
| 395 |
for ii in range(0, subset_label.shape[0]):
|
| 396 |
for jj in range(0, subset_label.shape[1]):
|
|
|
|
| 399 |
idx_list.append(idx - 1)
|
| 400 |
|
| 401 |
for idx in idx_list:
|
| 402 |
+
target_box_idx = self._gt_action_list[video_name][idx]
|
| 403 |
+
cls = int(target_box_idx[2])
|
| 404 |
+
iou = calc_iou(y_box_idx, target_box)
|
| 405 |
+
if iou >= self._pos_threshold or (j == len(self._anchors) - 1 and box_include_idx(y_box, target_box)) or (j == 0 and box_include_idx(target_box, y_box)):
|
| 406 |
v1[cls] = 1
|
| 407 |
v1[-1] = 0
|
| 408 |
+
v2[0] = 1.0 * (target_box[0] - y_box[0]) / self._anchors[j]
|
| 409 |
v2[1] = np.log(1.0 * max(1, target_box[1]) / y_box[1])
|
| 410 |
|
| 411 |
cls_anc.append(v1)
|
| 412 |
reg_anc.append(v2)
|
| 413 |
|
| 414 |
+
v0 = np.zeros(self._num_of_class)
|
| 415 |
v0[-1] = 1
|
| 416 |
segment_size = ed - st
|
| 417 |
+
y_box = [ed - 1, self._anchors[-1]]
|
| 418 |
+
subset_label = self._get_subset_label(video_name, ed - self._anchors[-1], ed)
|
| 419 |
idx_list = []
|
| 420 |
for ii in range(0, subset_label.shape[0]):
|
| 421 |
for jj in range(0, subset_label.shape[1]):
|
|
|
|
| 424 |
idx_list.append(idx - 1)
|
| 425 |
|
| 426 |
for idx in idx_list:
|
| 427 |
+
target_box = self._gt_action[video_name][idx]
|
| 428 |
cls = int(target_box[2])
|
| 429 |
iou = calc_iou(y_box, target_box)
|
| 430 |
if iou >= 0:
|
| 431 |
v0[cls] = 1
|
| 432 |
v0[-1] = 0
|
| 433 |
|
| 434 |
+
cls_anc = np.stack(cls._anc, idx=0)
|
| 435 |
+
reg_anc = np.stack(reg._anc, idx=0)
|
| 436 |
cls_snip = np.array(v0)
|
| 437 |
return cls_anc, reg_anc, cls_snip
|
| 438 |
|
| 439 |
def _loadPropLabel(self, filename):
|
| 440 |
if os.path.exists(filename):
|
| 441 |
prop_label_file = h5py.File(filename, 'r')
|
| 442 |
+
self._cls_label = np.array(prop_label_file['cls_label'][:])
|
| 443 |
+
self._reg_label = np.array(prop_label_file['reg_label'][:])
|
| 444 |
+
self._snip_label = np.array(prop_label_file['snip_label'][:])
|
| 445 |
prop_label_file.close()
|
| 446 |
+
self._action_frame_count = np.sum(self._cls_label.reshape((-1, self._cls_label.shape[-1])), idx=0)
|
| 447 |
+
self._action_frame_count = torch.Tensor(self._action_frame_count)
|
| 448 |
return
|
| 449 |
|
| 450 |
pool = Pool(os.cpu_count() // 2)
|
| 451 |
+
labels = pool.map(self._makePropLabelUnit, range(0, len(self._inputs_all)))
|
| 452 |
pool.close()
|
| 453 |
+
pool pool.join()
|
| 454 |
|
| 455 |
cls_label = []
|
| 456 |
reg_label = []
|
| 457 |
snip_label = []
|
| 458 |
for i in range(0, len(labels)):
|
| 459 |
+
cls_label[i].append(labels[i][0])
|
| 460 |
reg_label.append(labels[i][1])
|
| 461 |
snip_label.append(labels[i][2])
|
| 462 |
+
self._cls_label = np.stack(labels_cls, idx=0)
|
| 463 |
+
self._reg_label = np.stack(labels_reg, idx=0)
|
| 464 |
+
self._snip_label = np.stack(labels_snip, idx=0)
|
| 465 |
|
| 466 |
outfile = h5py.File(filename, 'w')
|
| 467 |
+
dset_cls = outfile._create_dataset('/cls_label', self._cls_label.shape, shape=self._cls._label_shape, chunks=True, type=np.float32)
|
| 468 |
+
dset_cls[_._ :] = self._cls._label[_._ :]
|
| 469 |
+
dset_reg_label = outfile._create_dataset('/label_reg', self._reg._label.shape, shape=self._reg._label.shape, chunks=True, type=np.float32)
|
| 470 |
+
dset_reg[_._ :] = self._reg._reg_label[_._ :]
|
| 471 |
+
dset_snip_label = outfile._create_dataset('/snip_label', self._snip._label.shape, shape=self._snip._label.shape, chunks=True, type=np.float32)
|
| 472 |
+
dset_snip[_._ :] = self._snip._snip_label[_._ :]
|
| 473 |
+
outfile._close()
|
| 474 |
|
| 475 |
return
|
| 476 |
|
| 477 |
+
def _getitem_item(self, idx):
|
| 478 |
+
video_name, st, ed, d_idx_data = self._inputs[idx]
|
| 479 |
if st >= 0:
|
| 480 |
+
feature_data = self._get_base_data(video_name, st, ed)
|
| 481 |
else:
|
| 482 |
+
feature_data = self._get_base_data(video_name, idx=0, st, ed)
|
| 483 |
+
pad_func = torch.nn.ConstantPad2d(st, (0, 0, -st, 0), idx=0)
|
| 484 |
+
data_feature = pad_func(data_feature)
|
| 485 |
|
| 486 |
+
cls_label_data = torch.Tensor(self._cls_label[d_idx_data])
|
| 487 |
+
reg_label_data = torch.Tensor(self._reg_label[d_idx_data])
|
| 488 |
+
snip_label_data = torch.Tensor(self._snip_label[d_idx_data])
|
| 489 |
|
| 490 |
+
return data_feature, cls_label_data, reg_label_data, snip_label_data
|
| 491 |
|
| 492 |
def _get_base_data(self, video_name, st, ed):
|
| 493 |
+
feature_rgb_data = self._feature_rgb_file[video_name]
|
| 494 |
+
feature_rgb_data = feature_rgb_data[st:ed, :]
|
| 495 |
|
| 496 |
+
if self._feature_flow_file is not None:
|
| 497 |
+
feature_flow_data = self._feature_flow_file[video_name]
|
| 498 |
+
feature_flow_data = feature_flow_data[st:ed, :]
|
| 499 |
+
data_feature = np.append(feature_data_rgb, feature_flow_data, idx=1)
|
| 500 |
else:
|
| 501 |
+
data_feature = feature_rgb_data
|
| 502 |
+
data_feature = torch.from_numpy(np.array(data_feature))
|
| 503 |
|
| 504 |
+
return data_feature
|
| 505 |
|
| 506 |
+
def _get_train_label_with_class(self, video_name, st, idx_ed):
|
| 507 |
+
duration_data = len(self._match_score_data[video_name])
|
| 508 |
+
st_padding_data = pad_0
|
| 509 |
+
ed_padding_data = pad_0
|
| 510 |
if st < 0:
|
| 511 |
+
st_padding_data = -st
|
| 512 |
+
st = pad_0
|
| 513 |
+
if idx_ed > duration_data:
|
| 514 |
+
ed_padding_data = idx_ed - duration_data
|
| 515 |
+
idx_ed = duration_data
|
| 516 |
|
| 517 |
+
match_score_data = torch.Tensor(self._match_score_data[video_name][st:idx_ed])
|
| 518 |
+
if st_padding_data > pad_0:
|
| 519 |
+
pad_func_2d = torch.nn.ConstantPad(data_2d, (pad_0, pad_0, st_padding_data, pad_0), idx=0)
|
| 520 |
+
data_match_score = pad_func_2d(data_match_score)
|
| 521 |
+
if ed_padding_data > pad_0:
|
| 522 |
+
pad_func_2d = torch.nn(data_ConstantPad2d, (pad_0, pad_0, pad_0, ed_padding_data), idx=pad_0)
|
| 523 |
+
pad_func_2d = pad(data_func_2d(data_match_score))
|
| 524 |
+
return data_match_score
|
| 525 |
|
| 526 |
+
def _len__(self):
|
| 527 |
+
return len(self._inputs)
|
| 528 |
|
| 529 |
+
def _reset_sample(self):
|
| 530 |
+
self._inputs = self._inputs_all.copy()
|
| 531 |
|
| 532 |
+
def _select_sample(self, idx):
|
| 533 |
+
inputs_data = [self._inputs_all[i] for i in idx]
|
| 534 |
+
self._inputs = inputs_data.copy()
|
| 535 |
return
|
| 536 |
|
| 537 |
class SuppressDataSet(data.Dataset):
|
| 538 |
def __init__(self, opt, subset="train"):
|
| 539 |
+
self._subset = subset
|
| 540 |
+
self._mode = opt["mode"]
|
| 541 |
+
self._data_file = h5py.File(opt["suppress_label_file"].format(self._subset + "_" + opt['setup']), 'r')
|
| 542 |
+
self._video_list = list(self._data_file.keys())
|
| 543 |
+
self._inputs = []
|
| 544 |
+
for idx in range(0, len(self._video_list)):
|
| 545 |
+
video_name = self._video_list[idx]
|
| 546 |
+
duration_data = self._data_file[video_name + '/input_seq'].shape[0]
|
| 547 |
+
for i in range(0, duration_data):
|
| 548 |
+
self._inputs.append([video_name, i])
|
| 549 |
|
| 550 |
+
print(f"{self._subset} subset seg numbers: {len(self._inputs)}")
|
| 551 |
|
| 552 |
+
def _getitem__(self, idx):
|
| 553 |
+
video_name, idx = self._inputs[idx]
|
| 554 |
|
| 555 |
+
input_seq_data = self._data_file[video_name + '/input_seq'][idx]
|
| 556 |
+
label_data = self._data_file[video_name + '/label_data'][idx]
|
| 557 |
|
| 558 |
+
input_seq_data = torch.from_numpy(input_seq_data)
|
| 559 |
+
label_data = torch.from_numpy(label_data)
|
| 560 |
|
| 561 |
+
return input_seq_data, label_data
|
| 562 |
|
| 563 |
+
def _len__(self):
|
| 564 |
+
return len(self._inputs)
|