New DFC scripts with Split First
This commit is contained in:
parent
2d6c399acd
commit
14e1d92c68
@ -1,8 +1,4 @@
|
||||
import numpy as np
|
||||
import yaml
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import ld2dap
|
||||
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None, split=1, split_dim=0):
|
||||
|
@ -9,33 +9,66 @@
|
||||
# TODO details
|
||||
|
||||
import numpy as np
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import ld2dap
|
||||
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None):
|
||||
# Parse parameters type
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None, split=1, split_dim=0):
|
||||
"""DFC Differential Attribute Profiles
|
||||
|
||||
Compute description vectors for parameters. Rasters can be splitted along
|
||||
`split_dim` before description proceeds.
|
||||
|
||||
"""
|
||||
|
||||
# Parse attribute type
|
||||
treshold = float(treshold)
|
||||
areas = None if areas is None else np.array(areas).astype(np.float).astype(np.int)
|
||||
sd = None if sd is None else np.array(sd).astype(np.float)
|
||||
moi = None if moi is None else np.array(moi).astype(np.float)
|
||||
|
||||
# Pipelines
|
||||
# Load and filter
|
||||
loader = ld2dap.LoadTIFF(rasters)
|
||||
dfc_filter = ld2dap.Treshold(treshold)
|
||||
normalize = ld2dap.Normalize(dtype=np.uint8)
|
||||
raw_out = ld2dap.RawOutput()
|
||||
|
||||
raw_out.input = normalize
|
||||
normalize.input = dfc_filter
|
||||
dfc_filter.input = loader
|
||||
aps = ld2dap.AttributeProfiles(area=areas, sd=sd, moi=moi)
|
||||
aps.input = dfc_filter
|
||||
differential = ld2dap.Differential()
|
||||
differential.input = aps
|
||||
out_vectors = ld2dap.RawOutput()
|
||||
out_vectors.input = differential
|
||||
raw_out.run()
|
||||
|
||||
# Compute vectors
|
||||
out_vectors.run()
|
||||
# Split
|
||||
n = split; d = split_dim
|
||||
|
||||
return out_vectors.data
|
||||
step = int(raw_out.data.shape[d] / n)
|
||||
view = np.moveaxis(raw_out.data, d, 0)
|
||||
cuts = list()
|
||||
for i in range(n):
|
||||
cut = np.moveaxis(view[i*step:(i+1)*step+1], 0, d)
|
||||
cuts.append(cut)
|
||||
|
||||
# Describe
|
||||
dcuts = list()
|
||||
for cut in cuts:
|
||||
rinp = ld2dap.RawInput(cut, raw_out.metadata)
|
||||
aps = ld2dap.AttributeProfiles(areas, sd, moi, normalize_to_dtype=False)
|
||||
diff = ld2dap.Differential()
|
||||
vout = ld2dap.RawOutput()
|
||||
|
||||
vout.input = diff
|
||||
diff.input = aps
|
||||
aps.input = rinp
|
||||
vout.run()
|
||||
|
||||
dcuts.append(vout.data)
|
||||
|
||||
# Merge
|
||||
descriptors = np.zeros(raw_out.data.shape[:2] + (dcuts[0].shape[-1],))
|
||||
view = np.moveaxis(descriptors, d, 0)
|
||||
|
||||
for i, cut in enumerate(dcuts):
|
||||
view[i*step:(i+1)*step+1] = np.moveaxis(cut, 0, d)
|
||||
|
||||
return descriptors
|
||||
|
||||
def version():
|
||||
return 'v0.0'
|
||||
|
@ -1,41 +1,74 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file dfc_dsdaps.py
|
||||
# \file dfc_daps.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 28 août 2018
|
||||
# \date 27 août 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
import numpy as np
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import ld2dap
|
||||
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None):
|
||||
# Parse parameters type
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None, split=1, split_dim=0):
|
||||
"""DFC Differential Self Dual Attribute Profiles
|
||||
|
||||
Compute description vectors for parameters. Rasters can be splitted along
|
||||
`split_dim` before description proceeds.
|
||||
|
||||
"""
|
||||
|
||||
# Parse attribute type
|
||||
treshold = float(treshold)
|
||||
areas = None if areas is None else np.array(areas).astype(np.float).astype(np.int)
|
||||
sd = None if sd is None else np.array(sd).astype(np.float)
|
||||
moi = None if moi is None else np.array(moi).astype(np.float)
|
||||
|
||||
# Pipelines
|
||||
# Load and filter
|
||||
loader = ld2dap.LoadTIFF(rasters)
|
||||
dfc_filter = ld2dap.Treshold(treshold)
|
||||
normalize = ld2dap.Normalize(dtype=np.uint8)
|
||||
raw_out = ld2dap.RawOutput()
|
||||
|
||||
raw_out.input = normalize
|
||||
normalize.input = dfc_filter
|
||||
dfc_filter.input = loader
|
||||
sdaps = ld2dap.SelfDualAttributeProfiles(area=areas, sd=sd, moi=moi)
|
||||
sdaps.input = dfc_filter
|
||||
differential = ld2dap.Differential()
|
||||
differential.input = sdaps
|
||||
out_vectors = ld2dap.RawOutput()
|
||||
out_vectors.input = differential
|
||||
raw_out.run()
|
||||
|
||||
# Compute vectors
|
||||
out_vectors.run()
|
||||
# Split
|
||||
n = split; d = split_dim
|
||||
|
||||
return out_vectors.data
|
||||
step = int(raw_out.data.shape[d] / n)
|
||||
view = np.moveaxis(raw_out.data, d, 0)
|
||||
cuts = list()
|
||||
for i in range(n):
|
||||
cut = np.moveaxis(view[i*step:(i+1)*step+1], 0, d)
|
||||
cuts.append(cut)
|
||||
|
||||
# Describe
|
||||
dcuts = list()
|
||||
for cut in cuts:
|
||||
rinp = ld2dap.RawInput(cut, raw_out.metadata)
|
||||
aps = ld2dap.SelfDualAttributeProfiles(areas, sd, moi, normalize_to_dtype=False)
|
||||
diff = ld2dap.Differential()
|
||||
vout = ld2dap.RawOutput()
|
||||
|
||||
vout.input = diff
|
||||
diff.input = aps
|
||||
aps.input = rinp
|
||||
vout.run()
|
||||
|
||||
dcuts.append(vout.data)
|
||||
|
||||
# Merge
|
||||
descriptors = np.zeros(raw_out.data.shape[:2] + (dcuts[0].shape[-1],))
|
||||
view = np.moveaxis(descriptors, d, 0)
|
||||
|
||||
for i, cut in enumerate(dcuts):
|
||||
view[i*step:(i+1)*step+1] = np.moveaxis(cut, 0, d)
|
||||
|
||||
return descriptors
|
||||
|
||||
def version():
|
||||
return 'v0.0'
|
||||
|
@ -9,32 +9,64 @@
|
||||
# TODO details
|
||||
|
||||
import numpy as np
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import ld2dap
|
||||
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None):
|
||||
# Parse parameters type
|
||||
def run(rasters, treshold=1e4, areas=None, sd=None, moi=None, split=1, split_dim=0):
|
||||
"""DFC Self Dual Attribute Profiles
|
||||
|
||||
Compute description vectors for parameters. Rasters can be splitted along
|
||||
`split_dim` before description proceeds.
|
||||
|
||||
"""
|
||||
|
||||
# Parse attribute type
|
||||
treshold = float(treshold)
|
||||
areas = None if areas is None else np.array(areas).astype(np.float).astype(np.int)
|
||||
sd = None if sd is None else np.array(sd).astype(np.float)
|
||||
moi = None if moi is None else np.array(moi).astype(np.float)
|
||||
|
||||
# Pipelines
|
||||
# Load and filter
|
||||
loader = ld2dap.LoadTIFF(rasters)
|
||||
dfc_filter = ld2dap.Treshold(treshold)
|
||||
normalize = ld2dap.Normalize(dtype=np.uint8)
|
||||
raw_out = ld2dap.RawOutput()
|
||||
|
||||
raw_out.input = normalize
|
||||
normalize.input = dfc_filter
|
||||
dfc_filter.input = loader
|
||||
sdaps = ld2dap.SelfDualAttributeProfiles(area=areas, sd=sd, moi=moi)
|
||||
sdaps.input = dfc_filter
|
||||
out_vectors = ld2dap.RawOutput()
|
||||
out_vectors.input = sdaps
|
||||
raw_out.run()
|
||||
|
||||
# Compute vectors
|
||||
out_vectors.run()
|
||||
# Split
|
||||
n = split; d = split_dim
|
||||
|
||||
return out_vectors.data
|
||||
step = int(raw_out.data.shape[d] / n)
|
||||
view = np.moveaxis(raw_out.data, d, 0)
|
||||
cuts = list()
|
||||
for i in range(n):
|
||||
cut = np.moveaxis(view[i*step:(i+1)*step+1], 0, d)
|
||||
cuts.append(cut)
|
||||
|
||||
# Describe
|
||||
dcuts = list()
|
||||
for cut in cuts:
|
||||
rinp = ld2dap.RawInput(cut, raw_out.metadata)
|
||||
aps = ld2dap.SelfDualAttributeProfiles(areas, sd, moi, normalize_to_dtype=False)
|
||||
vout = ld2dap.RawOutput()
|
||||
|
||||
vout.input = aps
|
||||
aps.input = rinp
|
||||
vout.run()
|
||||
|
||||
dcuts.append(vout.data)
|
||||
|
||||
# Merge
|
||||
descriptors = np.zeros(raw_out.data.shape[:2] + (dcuts[0].shape[-1],))
|
||||
view = np.moveaxis(descriptors, d, 0)
|
||||
|
||||
for i, cut in enumerate(dcuts):
|
||||
view[i*step:(i+1)*step+1] = np.moveaxis(cut, 0, d)
|
||||
|
||||
return descriptors
|
||||
|
||||
def version():
|
||||
return 'v0.0'
|
||||
|
||||
|
@ -15,14 +15,16 @@ expe:
|
||||
raster: ./Data/ground_truth/2018_IEEE_GRSS_DFC_GT_TR.tif
|
||||
meta_labels: ./Data/ground_truth/jurse_meta_idx.csv
|
||||
descriptors_script:
|
||||
name: descriptors.dfc_aps
|
||||
name: descriptors.dfc_sdaps
|
||||
parameters:
|
||||
split: 5
|
||||
split: 4
|
||||
areas:
|
||||
- 100
|
||||
- 1000
|
||||
- 1e4
|
||||
moi:
|
||||
- 0.5
|
||||
- 0.7
|
||||
- 0.9
|
||||
rasters:
|
||||
- ./Data/dfc_rasters/DEM+B_C123/UH17_GEM051_TR.tif
|
||||
@ -32,12 +34,12 @@ expe:
|
||||
name: Split
|
||||
package: cvgenerators.jurse
|
||||
parameters:
|
||||
n_test: 5
|
||||
n_test: 4
|
||||
classifier:
|
||||
name: RandomForestClassifier
|
||||
package: sklearn.ensemble
|
||||
parameters:
|
||||
min_samples_leaf: 10
|
||||
n_estimators: 10
|
||||
n_estimators: 100
|
||||
n_jobs: -1
|
||||
random_state: 0
|
||||
|
Loading…
Reference in New Issue
Block a user