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
bf584072
Unverified
Commit
bf584072
authored
Aug 03, 2020
by
Philip Meier
Committed by
GitHub
Aug 03, 2020
Browse files
add typehints for torchvision.datasets.sbd (#2535)
parent
49ec4a16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
13 deletions
+16
-13
torchvision/datasets/sbd.py
torchvision/datasets/sbd.py
+16
-13
No files found.
torchvision/datasets/sbd.py
View file @
bf584072
import
os
import
os
import
shutil
import
shutil
from
.vision
import
VisionDataset
from
.vision
import
VisionDataset
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
import
numpy
as
np
import
numpy
as
np
...
@@ -49,12 +50,14 @@ class SBDataset(VisionDataset):
...
@@ -49,12 +50,14 @@ class SBDataset(VisionDataset):
voc_split_filename
=
"train_noval.txt"
voc_split_filename
=
"train_noval.txt"
voc_split_md5
=
"79bff800c5f0b1ec6b21080a3c066722"
voc_split_md5
=
"79bff800c5f0b1ec6b21080a3c066722"
def
__init__
(
self
,
def
__init__
(
root
,
self
,
image_set
=
'train'
,
root
:
str
,
mode
=
'boundaries'
,
image_set
:
str
=
"train"
,
download
=
False
,
mode
:
str
=
"boundaries"
,
transforms
=
None
):
download
:
bool
=
False
,
transforms
:
Optional
[
Callable
]
=
None
,
)
->
None
:
try
:
try
:
from
scipy.io
import
loadmat
from
scipy.io
import
loadmat
...
@@ -88,8 +91,8 @@ class SBDataset(VisionDataset):
...
@@ -88,8 +91,8 @@ class SBDataset(VisionDataset):
split_f
=
os
.
path
.
join
(
sbd_root
,
image_set
.
rstrip
(
'
\n
'
)
+
'.txt'
)
split_f
=
os
.
path
.
join
(
sbd_root
,
image_set
.
rstrip
(
'
\n
'
)
+
'.txt'
)
with
open
(
os
.
path
.
join
(
split_f
),
"r"
)
as
f
:
with
open
(
os
.
path
.
join
(
split_f
),
"r"
)
as
f
h
:
file_names
=
[
x
.
strip
()
for
x
in
f
.
readlines
()]
file_names
=
[
x
.
strip
()
for
x
in
f
h
.
readlines
()]
self
.
images
=
[
os
.
path
.
join
(
image_dir
,
x
+
".jpg"
)
for
x
in
file_names
]
self
.
images
=
[
os
.
path
.
join
(
image_dir
,
x
+
".jpg"
)
for
x
in
file_names
]
self
.
masks
=
[
os
.
path
.
join
(
mask_dir
,
x
+
".mat"
)
for
x
in
file_names
]
self
.
masks
=
[
os
.
path
.
join
(
mask_dir
,
x
+
".mat"
)
for
x
in
file_names
]
...
@@ -98,16 +101,16 @@ class SBDataset(VisionDataset):
...
@@ -98,16 +101,16 @@ class SBDataset(VisionDataset):
self
.
_get_target
=
self
.
_get_segmentation_target
\
self
.
_get_target
=
self
.
_get_segmentation_target
\
if
self
.
mode
==
"segmentation"
else
self
.
_get_boundaries_target
if
self
.
mode
==
"segmentation"
else
self
.
_get_boundaries_target
def
_get_segmentation_target
(
self
,
filepath
)
:
def
_get_segmentation_target
(
self
,
filepath
:
str
)
->
Image
.
Image
:
mat
=
self
.
_loadmat
(
filepath
)
mat
=
self
.
_loadmat
(
filepath
)
return
Image
.
fromarray
(
mat
[
'GTcls'
][
0
][
'Segmentation'
][
0
])
return
Image
.
fromarray
(
mat
[
'GTcls'
][
0
][
'Segmentation'
][
0
])
def
_get_boundaries_target
(
self
,
filepath
)
:
def
_get_boundaries_target
(
self
,
filepath
:
str
)
->
np
.
ndarray
:
mat
=
self
.
_loadmat
(
filepath
)
mat
=
self
.
_loadmat
(
filepath
)
return
np
.
concatenate
([
np
.
expand_dims
(
mat
[
'GTcls'
][
0
][
'Boundaries'
][
0
][
i
][
0
].
toarray
(),
axis
=
0
)
return
np
.
concatenate
([
np
.
expand_dims
(
mat
[
'GTcls'
][
0
][
'Boundaries'
][
0
][
i
][
0
].
toarray
(),
axis
=
0
)
for
i
in
range
(
self
.
num_classes
)],
axis
=
0
)
for
i
in
range
(
self
.
num_classes
)],
axis
=
0
)
def
__getitem__
(
self
,
index
)
:
def
__getitem__
(
self
,
index
:
int
)
->
Tuple
[
Any
,
Any
]
:
img
=
Image
.
open
(
self
.
images
[
index
]).
convert
(
'RGB'
)
img
=
Image
.
open
(
self
.
images
[
index
]).
convert
(
'RGB'
)
target
=
self
.
_get_target
(
self
.
masks
[
index
])
target
=
self
.
_get_target
(
self
.
masks
[
index
])
...
@@ -116,9 +119,9 @@ class SBDataset(VisionDataset):
...
@@ -116,9 +119,9 @@ class SBDataset(VisionDataset):
return
img
,
target
return
img
,
target
def
__len__
(
self
):
def
__len__
(
self
)
->
int
:
return
len
(
self
.
images
)
return
len
(
self
.
images
)
def
extra_repr
(
self
):
def
extra_repr
(
self
)
->
str
:
lines
=
[
"Image set: {image_set}"
,
"Mode: {mode}"
]
lines
=
[
"Image set: {image_set}"
,
"Mode: {mode}"
]
return
'
\n
'
.
join
(
lines
).
format
(
**
self
.
__dict__
)
return
'
\n
'
.
join
(
lines
).
format
(
**
self
.
__dict__
)
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