Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySegCNN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
earth_observation_public
PySegCNN
Commits
5ddd6ab4
Commit
5ddd6ab4
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Added a generic CustomSubset; added supported dataset split enumeration
parent
2220de7c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/core/split.py
+21
-19
21 additions, 19 deletions
pysegcnn/core/split.py
with
21 additions
and
19 deletions
pysegcnn/core/split.py
+
21
−
19
View file @
5ddd6ab4
...
...
@@ -6,6 +6,7 @@ Created on Wed Jul 29 12:02:32 2020
"""
# builtins
import
datetime
import
enum
# externals
import
numpy
as
np
...
...
@@ -14,10 +15,6 @@ from torch.utils.data.dataset import Subset
# the names of the subsets
SUBSET_NAMES
=
[
'
train
'
,
'
valid
'
,
'
test
'
]
# valid split modes
VALID_SPLIT_MODES
=
[
'
random
'
,
'
scene
'
,
'
date
'
]
# function calculating number of samples in a dataset given a ratio
def
_ds_len
(
ds
,
ratio
):
return
int
(
np
.
round
(
len
(
ds
)
*
ratio
))
...
...
@@ -145,7 +142,19 @@ def pairwise_disjoint(sets):
return
n
==
len
(
union
)
class
SceneSubset
(
Subset
):
class
CustomSubset
(
Subset
):
def
__repr__
(
self
):
# representation string
fs
=
'
- {}: {:d} tiles ({:.2f}%)
'
.
format
(
self
.
name
,
len
(
self
.
scenes
),
100
*
len
(
self
.
scenes
)
/
len
(
self
.
dataset
))
return
fs
class
SceneSubset
(
CustomSubset
):
def
__init__
(
self
,
ds
,
indices
,
name
,
scenes
,
scene_ids
):
super
().
__init__
(
dataset
=
ds
,
indices
=
indices
)
...
...
@@ -160,7 +169,7 @@ class SceneSubset(Subset):
self
.
ids
=
scene_ids
class
RandomSubset
(
Subset
):
class
RandomSubset
(
Custom
Subset
):
def
__init__
(
self
,
ds
,
indices
,
name
,
scenes
,
scene_ids
):
super
().
__init__
(
dataset
=
ds
,
indices
=
indices
)
...
...
@@ -202,19 +211,6 @@ class Split(object):
def
subset_type
(
self
):
raise
NotImplementedError
def
__repr__
(
self
):
# representation string to print
fs
=
self
.
__class__
.
__name__
+
'
(
\n
'
# dataset split
fs
+=
'
\n
'
.
join
(
'
- {}: {:d} batches ({:.2f}%)
'
.
format
(
k
,
len
(
v
),
len
(
v
)
*
100
/
len
(
self
.
ds
))
for
k
,
v
in
self
.
subsets
().
items
())
fs
+=
'
\n
)
'
return
fs
class
DateSplit
(
Split
):
def
__init__
(
self
,
ds
,
date
,
dateformat
):
...
...
@@ -272,3 +268,9 @@ class RandomSceneSplit(RandomSplit):
def
subset_type
(
self
):
return
SceneSubset
class
SupportedSplits
(
enum
.
Enum
):
random
=
RandomTileSplit
scene
=
RandomSceneSplit
date
=
DateSplit
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment