Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
sec2.1_ml
deeplearning
Commits
0007d6f6
Commit
0007d6f6
authored
Aug 02, 2018
by
Marius Kriegerowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitext.gfz-potsdam.de:sec2.1_ml/deeplearning
parents
f88c1e68
9a64146e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
23 deletions
+62
-23
pinky/README.md
pinky/README.md
+18
-0
pinky/src/model.py
pinky/src/model.py
+3
-1
pinky/src/optimize.py
pinky/src/optimize.py
+41
-22
No files found.
pinky/README.md
View file @
0007d6f6
...
...
@@ -18,3 +18,21 @@ You can dump your examples to TFRecordDatasets to accelerate io operations:
and use the newly created config file to run
`--train`
Tests
-----
-
basic learning (synthetics, real data)
# TODO: split data -> training, evaluation
-
synthetics, layered cake, train with top and bottom layer containing events.
Validate with events within middle layer
-
evaluation using 'unknown' velocity model
-
test extrapolation with fault plane geometry
-
synthetic pretraining
-
hyperparameter optimization using skopt
Outlook
-------
-
increase z error weight -> improve z estimates
pinky/src/model.py
View file @
0007d6f6
...
...
@@ -68,6 +68,8 @@ class Model(Object):
:param kernel_width: convolution kernel size accross time axis
(Needs some debugging and checking)
TODO:
- cross_channel_kernel
'''
_
,
n_channels
,
n_samples
,
_
=
input
.
shape
...
...
@@ -113,7 +115,7 @@ class Model(Object):
# tf.summary.image('input', features)
for
ilayer
in
range
(
params
.
get
(
'n_layers'
,
3
)):
input
=
self
.
time_axis_cnn
(
input
,
n_filters
,
1
,
input
=
self
.
time_axis_cnn
(
input
,
n_filters
*
(
1
+
ilayer
)
,
1
,
kernel_width
=
int
(
kernel_width
+
ilayer
*
kernel_width_factor
),
name
=
'conv_%s'
%
ilayer
,
training
=
training
)
# conv = self.time_axis_cnn(conv, n_filters*2, 1, kernel_width=2, name='conv2',
...
...
pinky/src/optimize.py
View file @
0007d6f6
import
matplotlib
as
mpl
mpl
.
use
(
'PDF'
)
import
os
from
.util
import
delete_if_exists
from
skopt
import
gp_minimize
from
skopt
import
dump
as
dump_result
from
skopt
import
load
as
load_result
from
skopt.space
import
Real
,
Categorical
,
Integer
from
skopt.plots
import
plot_convergence
,
plot_objective_2D
# from skopt.plots import plot_convergence, plot_objective_2D
from
skopt.plots
import
plot_convergence
,
plot_objective
from
skopt.plots
import
plot_objective
,
plot_evaluations
import
matplotlib.pyplot
as
plt
import
logging
from
pyrocko.guts
import
Object
,
Int
,
Float
,
List
,
Tuple
,
String
try
:
from
skopt.plots
import
plot_histogram
_plot_histogram_error
=
False
except
ImportError
as
e
:
_plot_histogram_error
=
e
logger
.
debug
(
e
)
from
pyrocko.guts
import
Object
,
Int
,
Float
,
List
,
Tuple
,
String
import
logging
logging
.
debug
(
e
)
logger
=
logging
.
getLogger
()
...
...
@@ -30,6 +35,12 @@ class Optimizer(Object):
path_out
=
String
.
T
(
default
=
'optimizer-results'
,
help
=
'base path where to store results, plots and logs'
)
def
__init__
(
self
,
**
kwargs
):
'''
TODO:
- optimize kernel heigth (cross_channel_kernel)
'''
super
().
__init__
(
**
kwargs
)
self
.
model
=
None
self
.
result
=
None
...
...
@@ -101,17 +112,17 @@ class Optimizer(Object):
n_calls
=
self
.
n_calls
,
x0
=
self
.
optimizer_values
)
dump_result
(
self
.
result
,
self
.
fn_result
)
#
dump_result(self.result, self.fn_result)
self
.
evaluate_result
()
self
.
plot_results
()
def
ensure_result
(
self
):
''' Load and set minimizer result.'''
if
self
.
result
is
None
:
if
self
.
fn_result
is
None
:
logger
.
warn
(
'Cannot load results from filename: %s'
%
self
.
fn_result
)
self
.
result
=
load_result
(
self
.
fn_result
)
else
:
logger
.
warn
(
'Cannot load results from filename: %s'
%
self
.
fn_result
)
def
extend_path
(
self
,
*
path
):
'''Prepend `self.path_out` to `path`.'''
...
...
@@ -120,33 +131,41 @@ class Optimizer(Object):
def
evaluate_result
(
self
):
self
.
ensure_result
()
best
=
self
.
result
.
space
.
point_to_dict
(
self
.
result
.
x
)
# best = self.result.space.point_to_dict(self.result.x)
best
=
self
.
result
.
x
logger
.
info
(
'Best parameter set:'
)
logger
.
info
(
best
)
logger
.
info
(
'Best parameter loss:'
)
logger
.
info
(
self
.
result
.
fun
)
def
ensure_directory
(
self
,
directory
):
if
not
os
.
path
.
exists
(
directory
):
os
.
makedirs
(
directory
)
def
plot_results
(
self
):
'''Produce and save result plots. '''
self
.
ensure_result
()
self
.
ensure_directory
(
self
.
extend_path
(
'plots'
))
if
_plot_histogram_error
:
logger
.
warn
(
_plot_histogram_error
)
else
:
for
dim_name
in
self
.
optimizer_keys
:
fig
,
ax
=
plot_histogram
(
result
=
self
.
result
,
dimension_name
=
dim_name
)
fig
.
savefig
(
extend_path
(
'plots/histogram_%s.pdf'
%
dim_name
))
fig
,
ax
=
plot_objective
(
result
=
self
.
result
,
dimension_names
=
self
.
non_categorical_dimensions
)
fig
.
savefig
(
extend_path
(
'plots/objectives.pdf'
))
fig
,
ax
=
plot_evaluations
(
result
=
self
.
result
,
dimension_names
=
self
.
non_categorical_dimensions
)
fig
.
savefig
(
extend_path
(
'plots/evaluations.pdf'
))
fig
,
ax
=
plot_histogram
(
result
=
self
.
result
)
#, dimension_name=dim_name)
fig
.
savefig
(
self
.
extend_path
(
'plots/histogram_%s.pdf'
%
dim_name
))
ax
=
plot_objective
(
result
=
self
.
result
,)
# dimension_names=self.non_categorical_dimensions)
fig
=
plt
.
gcf
()
fig
.
savefig
(
self
.
extend_path
(
'plots/objectives.pdf'
))
ax
=
plot_evaluations
(
result
=
self
.
result
,)
# dimension_names=self.non_categorical_dimensions)
fig
=
plt
.
gcf
()
fig
.
savefig
(
self
.
extend_path
(
'plots/evaluations.pdf'
))
def
log_dir_name
(
self
,
params
):
'''Helper function to transform `params` into a logging directory
...
...
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