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
cf59d839
Unverified
Commit
cf59d839
authored
Mar 01, 2021
by
Philip Meier
Committed by
GitHub
Mar 01, 2021
Browse files
add tests for USPS dataset (#3466)
Co-authored-by:
Vasilis Vryniotis
<
datumbox@users.noreply.github.com
>
parent
1f17f5fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
test/test_datasets.py
test/test_datasets.py
+20
-0
No files found.
test/test_datasets.py
View file @
cf59d839
...
...
@@ -23,6 +23,7 @@ import torch
import
shutil
import
json
import
random
import
bz2
import
torch.nn.functional
as
F
import
string
import
io
...
...
@@ -1173,5 +1174,24 @@ class SEMEIONTestCase(datasets_utils.ImageDatasetTestCase):
return
num_images
class
USPSTestCase
(
datasets_utils
.
ImageDatasetTestCase
):
DATASET_CLASS
=
datasets
.
USPS
CONFIGS
=
datasets_utils
.
combinations_grid
(
train
=
(
True
,
False
))
def
inject_fake_data
(
self
,
tmpdir
,
config
):
num_images
=
2
if
config
[
"train"
]
else
1
images
=
torch
.
rand
(
num_images
,
256
)
*
2
-
1
labels
=
torch
.
randint
(
1
,
11
,
size
=
(
num_images
,))
with
bz2
.
open
(
pathlib
.
Path
(
tmpdir
)
/
f
"usps
{
'.t'
if
not
config
[
'train'
]
else
''
}
.bz2"
,
"w"
)
as
fh
:
for
image
,
label
in
zip
(
images
,
labels
):
line
=
" "
.
join
((
str
(
label
.
item
()),
*
[
f
"
{
idx
}
:
{
pixel
:.
6
f
}
"
for
idx
,
pixel
in
enumerate
(
image
,
1
)]))
fh
.
write
(
f
"
{
line
}
\n
"
.
encode
())
return
num_images
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