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
95226780
Unverified
Commit
95226780
authored
May 21, 2021
by
Philip Meier
Committed by
GitHub
May 21, 2021
Browse files
Remove obsolete test_datasets_transforms.py (#3867)
parent
7b87af25
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
72 deletions
+0
-72
test/test_datasets_transforms.py
test/test_datasets_transforms.py
+0
-72
No files found.
test/test_datasets_transforms.py
deleted
100644 → 0
View file @
7b87af25
import
os
import
shutil
import
contextlib
import
tempfile
import
unittest
from
torchvision.datasets
import
ImageFolder
FAKEDATA_DIR
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'assets'
,
'fakedata'
)
@
contextlib
.
contextmanager
def
tmp_dir
(
src
=
None
,
**
kwargs
):
tmp_dir
=
tempfile
.
mkdtemp
(
**
kwargs
)
if
src
is
not
None
:
os
.
rmdir
(
tmp_dir
)
shutil
.
copytree
(
src
,
tmp_dir
)
try
:
yield
tmp_dir
finally
:
shutil
.
rmtree
(
tmp_dir
)
def
mock_transform
(
return_value
,
arg_list
):
def
mock
(
arg
):
arg_list
.
append
(
arg
)
return
return_value
return
mock
class
Tester
(
unittest
.
TestCase
):
def
test_transform
(
self
):
with
tmp_dir
(
src
=
os
.
path
.
join
(
FAKEDATA_DIR
,
'imagefolder'
))
as
root
:
class_a_image_files
=
[
os
.
path
.
join
(
root
,
'a'
,
file
)
for
file
in
(
'a1.png'
,
'a2.png'
,
'a3.png'
)]
class_b_image_files
=
[
os
.
path
.
join
(
root
,
'b'
,
file
)
for
file
in
(
'b1.png'
,
'b2.png'
,
'b3.png'
,
'b4.png'
)]
return_value
=
os
.
path
.
join
(
root
,
'a'
,
'a1.png'
)
args
=
[]
transform
=
mock_transform
(
return_value
,
args
)
dataset
=
ImageFolder
(
root
,
loader
=
lambda
x
:
x
,
transform
=
transform
)
outputs
=
[
dataset
[
i
][
0
]
for
i
in
range
(
len
(
dataset
))]
self
.
assertEqual
([
return_value
]
*
len
(
outputs
),
outputs
)
imgs
=
sorted
(
class_a_image_files
+
class_b_image_files
)
self
.
assertEqual
(
imgs
,
sorted
(
args
))
def
test_target_transform
(
self
):
with
tmp_dir
(
src
=
os
.
path
.
join
(
FAKEDATA_DIR
,
'imagefolder'
))
as
root
:
class_a_image_files
=
[
os
.
path
.
join
(
root
,
'a'
,
file
)
for
file
in
(
'a1.png'
,
'a2.png'
,
'a3.png'
)]
class_b_image_files
=
[
os
.
path
.
join
(
root
,
'b'
,
file
)
for
file
in
(
'b1.png'
,
'b2.png'
,
'b3.png'
,
'b4.png'
)]
return_value
=
os
.
path
.
join
(
root
,
'a'
,
'a1.png'
)
args
=
[]
target_transform
=
mock_transform
(
return_value
,
args
)
dataset
=
ImageFolder
(
root
,
loader
=
lambda
x
:
x
,
target_transform
=
target_transform
)
outputs
=
[
dataset
[
i
][
1
]
for
i
in
range
(
len
(
dataset
))]
self
.
assertEqual
([
return_value
]
*
len
(
outputs
),
outputs
)
class_a_idx
=
dataset
.
class_to_idx
[
'a'
]
class_b_idx
=
dataset
.
class_to_idx
[
'b'
]
targets
=
sorted
([
class_a_idx
]
*
len
(
class_a_image_files
)
+
[
class_b_idx
]
*
len
(
class_b_image_files
))
self
.
assertEqual
(
targets
,
sorted
(
args
))
if
__name__
==
'__main__'
:
unittest
.
main
()
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