Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix#306 #317

Merged
merged 9 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions mmaction/datasets/pipelines/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,28 +417,11 @@ def __init__(self, clip_len, frame_interval=2, test_mode=False):
super().__init__(clip_len, frame_interval, test_mode=test_mode)

def _get_clips(self, center_index, skip_offsets, shot_info):
frame_inds = list()
ori_clip_len = self.clip_len * self.frame_interval

cur = center_index - self.frame_interval
length = len(
range(-self.frame_interval,
-(ori_clip_len + 1) // self.frame_interval,
-self.frame_interval))

for i in range(length):
frame_inds.append(cur + skip_offsets[i])
if cur - self.frame_interval >= shot_info[0]:
cur -= self.frame_interval

cur = center_index
length = len(
range(0, (ori_clip_len + 1) // self.frame_interval,
self.frame_interval))
for i in range(length):
frame_inds.append(cur + skip_offsets[i])
if cur + self.frame_interval < shot_info[1]:
cur += self.frame_interval
start = center_index - (self.clip_len // 2) * self.frame_interval
end = center_index + ((self.clip_len + 1) // 2) * self.frame_interval
frame_inds = list(range(start, end, self.frame_interval))
frame_inds = frame_inds + skip_offsets
frame_inds = np.clip(frame_inds, shot_info[0], shot_info[1] - 1)

return frame_inds

Expand All @@ -449,8 +432,10 @@ def __call__(self, results):
shot_info = results['shot_info']

center_index = fps * (timestamp - timestamp_start) + 1

skip_offsets = np.random.randint(
self.frame_interval, size=self.clip_len)
-self.frame_interval // 2, (self.frame_interval + 1) // 2,
size=self.clip_len)
frame_inds = self._get_clips(center_index, skip_offsets, shot_info)

results['frame_inds'] = np.array(frame_inds, dtype=np.int)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_data/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def test_sample_ava_frames(self):
assert ava_result['frame_interval'] == 2
assert len(ava_result['frame_inds']) == 32

# add test case in Issue #306
config = dict(clip_len=8, frame_interval=8)
sample_ava_dataset = SampleAVAFrames(**config)
ava_result = sample_ava_dataset(results=self.ava_results)
assert self.check_keys_contain(ava_result.keys(), target_keys)
assert ava_result['clip_len'] == 8
assert ava_result['frame_interval'] == 8
assert len(ava_result['frame_inds']) == 8

def test_sample_proposal_frames(self):
target_keys = [
'frame_inds', 'clip_len', 'frame_interval', 'num_clips',
Expand Down