-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shashank
authored and
Shashank
committed
Feb 18, 2023
1 parent
029f34c
commit 8b2b129
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2022 EVA | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
import unittest | ||
from test.util import ( | ||
FRAME_SIZE, | ||
NUM_FRAMES, | ||
create_dummy_batches, | ||
create_sample_video, | ||
file_remove, | ||
upload_dir_from_config, | ||
) | ||
|
||
from eva.expression.abstract_expression import ExpressionType | ||
from eva.expression.comparison_expression import ComparisonExpression | ||
from eva.expression.constant_value_expression import ConstantValueExpression | ||
from eva.expression.logical_expression import LogicalExpression | ||
from eva.expression.tuple_value_expression import TupleValueExpression | ||
from eva.readers.decord_reader import DecordReader | ||
|
||
|
||
class DecordLoaderTest(unittest.TestCase): | ||
def setUp(self): | ||
create_sample_video() | ||
|
||
def tearDown(self): | ||
file_remove("dummy.avi") | ||
|
||
def test_should_sample_every_k_frame(self): | ||
for k in range(1, 10): | ||
video_loader = DecordReader( | ||
file_url=os.path.join(upload_dir_from_config, "dummy.avi"), | ||
batch_mem_size=FRAME_SIZE * NUM_FRAMES, | ||
sampling_rate=k, | ||
) | ||
batches = list(video_loader.read()) | ||
expected = list( | ||
create_dummy_batches(filters=[i for i in range(0, NUM_FRAMES, k)]) | ||
) | ||
self.assertTrue(batches, expected) | ||
|
||
def test_should_sample_every_k_frame_with_predicate(self): | ||
col = TupleValueExpression("id") | ||
val = ConstantValueExpression(NUM_FRAMES // 2) | ||
predicate = ComparisonExpression( | ||
ExpressionType.COMPARE_GEQ, left=col, right=val | ||
) | ||
for k in range(2, 4): | ||
video_loader = DecordReader( | ||
file_url=os.path.join(upload_dir_from_config, "dummy.avi"), | ||
batch_mem_size=FRAME_SIZE * NUM_FRAMES, | ||
sampling_rate=k, | ||
predicate=predicate, | ||
) | ||
batches = list(video_loader.read()) | ||
for batch in batches: | ||
print(batch) | ||
value = NUM_FRAMES // 2 | ||
start = value + k - (value % k) if value % k else value | ||
expected = list( | ||
create_dummy_batches(filters=[i for i in range(start, NUM_FRAMES, k)]) | ||
) | ||
self.assertTrue(batches, expected) | ||
|
||
value = 2 | ||
predicate_1 = ComparisonExpression( | ||
ExpressionType.COMPARE_GEQ, | ||
left=TupleValueExpression("id"), | ||
right=ConstantValueExpression(value), | ||
) | ||
predicate_2 = ComparisonExpression( | ||
ExpressionType.COMPARE_LEQ, | ||
left=TupleValueExpression("id"), | ||
right=ConstantValueExpression(8), | ||
) | ||
predicate = LogicalExpression( | ||
ExpressionType.LOGICAL_AND, predicate_1, predicate_2 | ||
) | ||
for k in range(2, 4): | ||
video_loader = DecordReader( | ||
file_url=os.path.join(upload_dir_from_config, "dummy.avi"), | ||
batch_mem_size=FRAME_SIZE * NUM_FRAMES, | ||
sampling_rate=k, | ||
predicate=predicate, | ||
) | ||
batches = list(video_loader.read()) | ||
start = value + k - (value % k) if value % k else value | ||
expected = list( | ||
create_dummy_batches(filters=[i for i in range(start, 8, k)]) | ||
) | ||
self.assertTrue(batches, expected) |