Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
093757db
Unverified
Commit
093757db
authored
Jun 10, 2021
by
Vivek Kumar
Committed by
GitHub
Jun 10, 2021
Browse files
Port test_datasets_samplers.py to pytest (#4037)
parent
13ed657d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
test/test_datasets_samplers.py
test/test_datasets_samplers.py
+12
-12
No files found.
test/test_datasets_samplers.py
View file @
093757db
...
@@ -2,7 +2,7 @@ import contextlib
...
@@ -2,7 +2,7 @@ import contextlib
import
sys
import
sys
import
os
import
os
import
torch
import
torch
import
unit
test
import
py
test
from
torchvision
import
io
from
torchvision
import
io
from
torchvision.datasets.samplers
import
(
from
torchvision.datasets.samplers
import
(
...
@@ -38,13 +38,13 @@ def get_list_of_videos(num_videos=5, sizes=None, fps=None):
...
@@ -38,13 +38,13 @@ def get_list_of_videos(num_videos=5, sizes=None, fps=None):
yield
names
yield
names
@
unit
test
.
skip
I
f
(
not
io
.
video
.
_av_available
(),
"this test requires av"
)
@
py
test
.
mark
.
skip
i
f
(
not
io
.
video
.
_av_available
(),
reason
=
"this test requires av"
)
class
Test
er
(
unittest
.
TestCase
)
:
class
Test
DatasetsSamplers
:
def
test_random_clip_sampler
(
self
):
def
test_random_clip_sampler
(
self
):
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
25
,
25
,
25
])
as
video_list
:
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
25
,
25
,
25
])
as
video_list
:
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
sampler
=
RandomClipSampler
(
video_clips
,
3
)
sampler
=
RandomClipSampler
(
video_clips
,
3
)
self
.
assert
Equal
(
len
(
sampler
)
,
3
*
3
)
assert
len
(
sampler
)
==
3
*
3
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
videos
=
torch
.
div
(
indices
,
5
,
rounding_mode
=
'floor'
)
videos
=
torch
.
div
(
indices
,
5
,
rounding_mode
=
'floor'
)
v_idxs
,
count
=
torch
.
unique
(
videos
,
return_counts
=
True
)
v_idxs
,
count
=
torch
.
unique
(
videos
,
return_counts
=
True
)
...
@@ -55,10 +55,10 @@ class Tester(unittest.TestCase):
...
@@ -55,10 +55,10 @@ class Tester(unittest.TestCase):
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
10
,
25
,
25
])
as
video_list
:
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
10
,
25
,
25
])
as
video_list
:
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
sampler
=
RandomClipSampler
(
video_clips
,
3
)
sampler
=
RandomClipSampler
(
video_clips
,
3
)
self
.
assert
Equal
(
len
(
sampler
)
,
2
+
3
+
3
)
assert
len
(
sampler
)
==
2
+
3
+
3
indices
=
list
(
iter
(
sampler
))
indices
=
list
(
iter
(
sampler
))
self
.
assert
In
(
0
,
indices
)
assert
0
in
indices
self
.
assert
In
(
1
,
indices
)
assert
1
in
indices
# remove elements of the first video, to simplify testing
# remove elements of the first video, to simplify testing
indices
.
remove
(
0
)
indices
.
remove
(
0
)
indices
.
remove
(
1
)
indices
.
remove
(
1
)
...
@@ -72,7 +72,7 @@ class Tester(unittest.TestCase):
...
@@ -72,7 +72,7 @@ class Tester(unittest.TestCase):
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
25
,
25
,
25
])
as
video_list
:
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
25
,
25
,
25
])
as
video_list
:
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
sampler
=
UniformClipSampler
(
video_clips
,
3
)
sampler
=
UniformClipSampler
(
video_clips
,
3
)
self
.
assert
Equal
(
len
(
sampler
)
,
3
*
3
)
assert
len
(
sampler
)
==
3
*
3
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
videos
=
torch
.
div
(
indices
,
5
,
rounding_mode
=
'floor'
)
videos
=
torch
.
div
(
indices
,
5
,
rounding_mode
=
'floor'
)
v_idxs
,
count
=
torch
.
unique
(
videos
,
return_counts
=
True
)
v_idxs
,
count
=
torch
.
unique
(
videos
,
return_counts
=
True
)
...
@@ -84,7 +84,7 @@ class Tester(unittest.TestCase):
...
@@ -84,7 +84,7 @@ class Tester(unittest.TestCase):
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
10
,
25
,
25
])
as
video_list
:
with
get_list_of_videos
(
num_videos
=
3
,
sizes
=
[
10
,
25
,
25
])
as
video_list
:
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
video_clips
=
VideoClips
(
video_list
,
5
,
5
)
sampler
=
UniformClipSampler
(
video_clips
,
3
)
sampler
=
UniformClipSampler
(
video_clips
,
3
)
self
.
assert
Equal
(
len
(
sampler
)
,
3
*
3
)
assert
len
(
sampler
)
==
3
*
3
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
indices
=
torch
.
tensor
(
list
(
iter
(
sampler
)))
assert_equal
(
indices
,
torch
.
tensor
([
0
,
0
,
1
,
2
,
4
,
6
,
7
,
9
,
11
]))
assert_equal
(
indices
,
torch
.
tensor
([
0
,
0
,
1
,
2
,
4
,
6
,
7
,
9
,
11
]))
...
@@ -100,7 +100,7 @@ class Tester(unittest.TestCase):
...
@@ -100,7 +100,7 @@ class Tester(unittest.TestCase):
group_size
=
3
,
group_size
=
3
,
)
)
indices
=
torch
.
tensor
(
list
(
iter
(
distributed_sampler_rank0
)))
indices
=
torch
.
tensor
(
list
(
iter
(
distributed_sampler_rank0
)))
self
.
assert
Equal
(
len
(
distributed_sampler_rank0
)
,
6
)
assert
len
(
distributed_sampler_rank0
)
==
6
assert_equal
(
indices
,
torch
.
tensor
([
0
,
2
,
4
,
10
,
12
,
14
]))
assert_equal
(
indices
,
torch
.
tensor
([
0
,
2
,
4
,
10
,
12
,
14
]))
distributed_sampler_rank1
=
DistributedSampler
(
distributed_sampler_rank1
=
DistributedSampler
(
...
@@ -110,9 +110,9 @@ class Tester(unittest.TestCase):
...
@@ -110,9 +110,9 @@ class Tester(unittest.TestCase):
group_size
=
3
,
group_size
=
3
,
)
)
indices
=
torch
.
tensor
(
list
(
iter
(
distributed_sampler_rank1
)))
indices
=
torch
.
tensor
(
list
(
iter
(
distributed_sampler_rank1
)))
self
.
assert
Equal
(
len
(
distributed_sampler_rank1
)
,
6
)
assert
len
(
distributed_sampler_rank1
)
==
6
assert_equal
(
indices
,
torch
.
tensor
([
5
,
7
,
9
,
0
,
2
,
4
]))
assert_equal
(
indices
,
torch
.
tensor
([
5
,
7
,
9
,
0
,
2
,
4
]))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unit
test
.
main
()
py
test
.
main
(
[
__file__
]
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment