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
5dacadea
Commit
5dacadea
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Implemented the computation of the spectral distribution of the different classes.
parent
b924fadd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/core/dataset.py
+38
-7
38 additions, 7 deletions
pysegcnn/core/dataset.py
with
38 additions
and
7 deletions
pysegcnn/core/dataset.py
+
38
−
7
View file @
5dacadea
...
@@ -32,6 +32,7 @@ import pathlib
...
@@ -32,6 +32,7 @@ import pathlib
# externals
# externals
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
torch
import
torch
from
torch.utils.data
import
Dataset
from
torch.utils.data
import
Dataset
...
@@ -40,7 +41,8 @@ from pysegcnn.core.constants import (MultiSpectralSensor, Landsat8, Sentinel2,
...
@@ -40,7 +41,8 @@ from pysegcnn.core.constants import (MultiSpectralSensor, Landsat8, Sentinel2,
Label
,
SparcsLabels
,
Cloud95Labels
,
Label
,
SparcsLabels
,
Cloud95Labels
,
AlcdLabels
)
AlcdLabels
)
from
pysegcnn.core.utils
import
(
img2np
,
is_divisible
,
tile_topleft_corner
,
from
pysegcnn.core.utils
import
(
img2np
,
is_divisible
,
tile_topleft_corner
,
parse_landsat_scene
,
parse_sentinel2_scene
)
parse_landsat_scene
,
parse_sentinel2_scene
,
array_replace
)
# module level logger
# module level logger
LOGGER
=
logging
.
getLogger
(
__name__
)
LOGGER
=
logging
.
getLogger
(
__name__
)
...
@@ -210,13 +212,12 @@ class ImageDataset(Dataset):
...
@@ -210,13 +212,12 @@ class ImageDataset(Dataset):
# always use the original dataset together with the augmentations
# always use the original dataset together with the augmentations
self
.
transforms
=
[
None
]
+
self
.
transforms
self
.
transforms
=
[
None
]
+
self
.
transforms
# when padding, add a new "no data" label to the ground truth
# when padding, add a new "padded" label to the ground truth
self
.
cval
=
self
.
label_class
.
No_data
.
id
if
self
.
pad
and
sum
(
self
.
padding
)
>
0
:
if
self
.
pad
and
sum
(
self
.
padding
)
>
0
:
LOGGER
.
info
(
'
Adding label
"
No data
"
with value={} to ground truth.
'
self
.
cval
=
self
.
label_class
.
No_data
.
id
LOGGER
.
info
(
'
Padding to defined tile size. Padding value: {}.
'
.
format
(
self
.
cval
))
.
format
(
self
.
cval
))
else
:
else
:
# self._labels.pop(self.cval)
self
.
cval
=
0
self
.
cval
=
0
# remove labels to merge from dataset instance labels
# remove labels to merge from dataset instance labels
...
@@ -629,6 +630,35 @@ class ImageDataset(Dataset):
...
@@ -629,6 +630,35 @@ class ImageDataset(Dataset):
"""
"""
return
torch
.
tensor
(
np
.
asarray
(
x
).
copy
(),
dtype
=
dtype
)
return
torch
.
tensor
(
np
.
asarray
(
x
).
copy
(),
dtype
=
dtype
)
def
class_distribution
(
self
):
# initialize class distribution dataframe
columns
=
[
band
.
capitalize
()
for
band
in
self
.
use_bands
]
+
[
'
Class
'
]
cls_df
=
pd
.
DataFrame
(
columns
=
columns
)
# create the lookup table to replace the class identifiers by their
# corresponding labels
lookup
=
np
.
array
(
list
({
k
:
v
[
'
label
'
]
for
k
,
v
in
self
.
labels
.
items
()}
.
items
())).
astype
(
object
)
# iterate over the samples of the dataset
for
i
in
range
(
len
(
self
)):
# get the data of the current sample
LOGGER
.
info
(
'
Sample: {}/{}
'
.
format
(
i
+
1
,
len
(
self
)))
x
,
y
=
self
[
i
]
# reshape the current sample
data
=
np
.
hstack
([
x
.
flatten
(
start_dim
=
1
).
T
,
np
.
expand_dims
(
array_replace
(
y
.
flatten
(),
lookup
),
axis
=
1
)])
# the pixels of the current sample to the dataframe
df
=
pd
.
DataFrame
(
data
,
columns
=
columns
)
# update class distribution dataframe
cls_df
=
cls_df
.
append
(
df
)
return
cls_df
def
__repr__
(
self
):
def
__repr__
(
self
):
"""
Dataset representation.
"""
Dataset representation.
...
@@ -659,8 +689,9 @@ class ImageDataset(Dataset):
...
@@ -659,8 +689,9 @@ class ImageDataset(Dataset):
# tiles
# tiles
fs
+=
'
\n
(tiles):
\n
'
fs
+=
'
\n
(tiles):
\n
'
fs
+=
'
- number of tiles per scene: {}
\n
'
.
format
(
self
.
tiles
)
fs
+=
'
- number of tiles per scene: {}
\n
'
.
format
(
self
.
tiles
)
fs
+=
'
- tile size: {}
\n
'
.
format
((
self
.
tile_size
,
fs
+=
'
- tile size: {}
\n
'
.
format
(
self
.
tile_size
))
2
*
(
self
.
tile_size
,
)
if
self
.
tile_size
is
not
None
else
(
self
.
height
,
self
.
width
))
fs
+=
'
- number of tiles: {}
'
.
format
(
len
(
self
.
scenes
))
fs
+=
'
- number of tiles: {}
'
.
format
(
len
(
self
.
scenes
))
# classes of interest
# classes of interest
...
...
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