Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Tom Rink
python
Commits
d9e49e96
Commit
d9e49e96
authored
3 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
initial commit of flight altitude support
parent
0b0ce4aa
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
modules/deeplearning/icing_cnn.py
+32
-30
32 additions, 30 deletions
modules/deeplearning/icing_cnn.py
with
32 additions
and
30 deletions
modules/deeplearning/icing_cnn.py
+
32
−
30
View file @
d9e49e96
...
@@ -207,6 +207,7 @@ class IcingIntensityNN:
...
@@ -207,6 +207,7 @@ class IcingIntensityNN:
self
.
X_img
=
tf
.
keras
.
Input
(
shape
=
(
img_width
,
img_width
,
n_chans
))
self
.
X_img
=
tf
.
keras
.
Input
(
shape
=
(
img_width
,
img_width
,
n_chans
))
self
.
inputs
.
append
(
self
.
X_img
)
self
.
inputs
.
append
(
self
.
X_img
)
self
.
inputs
.
append
(
tf
.
keras
.
Input
(
5
))
self
.
DISK_CACHE
=
False
self
.
DISK_CACHE
=
False
...
@@ -218,8 +219,7 @@ class IcingIntensityNN:
...
@@ -218,8 +219,7 @@ class IcingIntensityNN:
tf
.
debugging
.
set_log_device_placement
(
LOG_DEVICE_PLACEMENT
)
tf
.
debugging
.
set_log_device_placement
(
LOG_DEVICE_PLACEMENT
)
# Note: Don't do this anymore, because nobody else willing to do so as well!
# Doesn't seem to play well with SLURM
# Also, doesn't seem to play well with SLURM
# gpus = tf.config.experimental.list_physical_devices('GPU')
# gpus = tf.config.experimental.list_physical_devices('GPU')
# if gpus:
# if gpus:
# try:
# try:
...
@@ -242,7 +242,7 @@ class IcingIntensityNN:
...
@@ -242,7 +242,7 @@ class IcingIntensityNN:
else
:
else
:
tup
=
self
.
in_mem_data_cache_test
(
key
)
tup
=
self
.
in_mem_data_cache_test
(
key
)
if
tup
is
not
None
:
if
tup
is
not
None
:
return
tup
[
0
],
tup
[
1
]
return
tup
[
0
],
tup
[
1
]
,
tup
[
2
]
# sort these to use as numpy indexing arrays
# sort these to use as numpy indexing arrays
nd_idxs
=
np
.
array
(
idxs
)
nd_idxs
=
np
.
array
(
idxs
)
...
@@ -268,6 +268,8 @@ class IcingIntensityNN:
...
@@ -268,6 +268,8 @@ class IcingIntensityNN:
data
=
data
.
astype
(
np
.
float32
)
data
=
data
.
astype
(
np
.
float32
)
data
=
np
.
transpose
(
data
,
axes
=
(
1
,
2
,
3
,
0
))
data
=
np
.
transpose
(
data
,
axes
=
(
1
,
2
,
3
,
0
))
data_alt
=
self
.
get_scalar_data
(
nd_idxs
,
is_training
)
label
=
self
.
get_label_data
(
nd_idxs
,
is_training
)
label
=
self
.
get_label_data
(
nd_idxs
,
is_training
)
label
=
np
.
where
(
label
==
-
1
,
0
,
label
)
label
=
np
.
where
(
label
==
-
1
,
0
,
label
)
...
@@ -282,11 +284,11 @@ class IcingIntensityNN:
...
@@ -282,11 +284,11 @@ class IcingIntensityNN:
if
CACHE_DATA_IN_MEM
:
if
CACHE_DATA_IN_MEM
:
if
is_training
:
if
is_training
:
self
.
in_mem_data_cache
[
key
]
=
(
data
,
label
)
self
.
in_mem_data_cache
[
key
]
=
(
data
,
data_alt
,
label
)
else
:
else
:
self
.
in_mem_data_cache_test
[
key
]
=
(
data
,
label
)
self
.
in_mem_data_cache_test
[
key
]
=
(
data
,
data_alt
,
label
)
return
data
,
label
return
data
,
data_alt
,
label
def
get_parameter_data
(
self
,
param
,
nd_idxs
,
is_training
):
def
get_parameter_data
(
self
,
param
,
nd_idxs
,
is_training
):
if
is_training
:
if
is_training
:
...
@@ -318,16 +320,13 @@ class IcingIntensityNN:
...
@@ -318,16 +320,13 @@ class IcingIntensityNN:
h5f
=
self
.
h5f_l2_tst
h5f
=
self
.
h5f_l2_tst
nda
=
h5f
[
param
][
nd_idxs
,]
nda
=
h5f
[
param
][
nd_idxs
,]
b0
=
np
.
logical_and
(
nda
>=
0
,
nda
<
2000
)
b1
=
np
.
logical_and
(
nda
>=
2000
,
nda
<
4000
)
nda
[
np
.
logical_and
(
nda
>=
0
,
nda
<
2000
)]
=
0
b2
=
np
.
logical_and
(
nda
>=
4000
,
nda
<
6000
)
nda
[
np
.
logical_and
(
nda
>=
2000
,
nda
<
4000
)]
=
1
b3
=
np
.
logical_and
(
nda
>=
6000
,
nda
<
8000
)
nda
[
np
.
logical_and
(
nda
>=
4000
,
nda
<
6000
)]
=
2
b4
=
np
.
logical_and
(
nda
>=
8000
,
nda
<
15000
)
nda
[
np
.
logical_and
(
nda
>=
6000
,
nda
<
8000
)]
=
3
nda
[
b0
]
=
0
nda
[
np
.
logical_and
(
nda
>=
8000
,
nda
<
15000
)]
=
4
nda
[
b1
]
=
1
nda
[
b2
]
=
2
nda
[
b3
]
=
3
nda
[
b4
]
=
4
nda
=
tf
.
one_hot
(
nda
,
5
).
numpy
()
nda
=
tf
.
one_hot
(
nda
,
5
).
numpy
()
return
nda
return
nda
...
@@ -368,21 +367,23 @@ class IcingIntensityNN:
...
@@ -368,21 +367,23 @@ class IcingIntensityNN:
data
=
np
.
stack
(
data
)
data
=
np
.
stack
(
data
)
data
=
data
.
astype
(
np
.
float32
)
data
=
data
.
astype
(
np
.
float32
)
data
=
np
.
transpose
(
data
,
axes
=
(
1
,
2
,
3
,
0
))
data
=
np
.
transpose
(
data
,
axes
=
(
1
,
2
,
3
,
0
))
# TODO: altitude data will be specified by user at run-time
return
data
return
data
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
def
data_function
(
self
,
indexes
):
def
data_function
(
self
,
indexes
):
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_train
,
[
indexes
],
[
tf
.
float32
,
tf
.
int32
])
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_train
,
[
indexes
],
[
tf
.
float32
,
tf
.
float32
,
tf
.
int32
])
return
out
return
out
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
def
data_function_test
(
self
,
indexes
):
def
data_function_test
(
self
,
indexes
):
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_test
,
[
indexes
],
[
tf
.
float32
,
tf
.
int32
])
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_test
,
[
indexes
],
[
tf
.
float32
,
tf
.
float32
,
tf
.
int32
])
return
out
return
out
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
@tf.function
(
input_signature
=
[
tf
.
TensorSpec
(
None
,
tf
.
int32
)])
def
data_function_evaluate
(
self
,
indexes
):
def
data_function_evaluate
(
self
,
indexes
):
# TODO: modify for user specified altitude
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_eval
,
[
indexes
],
tf
.
float32
)
out
=
tf
.
numpy_function
(
self
.
get_in_mem_data_batch_eval
,
[
indexes
],
tf
.
float32
)
return
out
return
out
...
@@ -666,8 +667,8 @@ class IcingIntensityNN:
...
@@ -666,8 +667,8 @@ class IcingIntensityNN:
@tf.function
@tf.function
def
train_step
(
self
,
mini_batch
):
def
train_step
(
self
,
mini_batch
):
inputs
=
[
mini_batch
[
0
]]
inputs
=
[
mini_batch
[
0
]
,
mini_batch
[
1
]
]
labels
=
mini_batch
[
1
]
labels
=
mini_batch
[
2
]
with
tf
.
GradientTape
()
as
tape
:
with
tf
.
GradientTape
()
as
tape
:
pred
=
self
.
model
(
inputs
,
training
=
True
)
pred
=
self
.
model
(
inputs
,
training
=
True
)
loss
=
self
.
loss
(
labels
,
pred
)
loss
=
self
.
loss
(
labels
,
pred
)
...
@@ -685,8 +686,8 @@ class IcingIntensityNN:
...
@@ -685,8 +686,8 @@ class IcingIntensityNN:
@tf.function
@tf.function
def
test_step
(
self
,
mini_batch
):
def
test_step
(
self
,
mini_batch
):
inputs
=
[
mini_batch
[
0
]]
inputs
=
[
mini_batch
[
0
]
,
mini_batch
[
1
]
]
labels
=
mini_batch
[
1
]
labels
=
mini_batch
[
2
]
pred
=
self
.
model
(
inputs
,
training
=
False
)
pred
=
self
.
model
(
inputs
,
training
=
False
)
t_loss
=
self
.
loss
(
labels
,
pred
)
t_loss
=
self
.
loss
(
labels
,
pred
)
...
@@ -702,8 +703,8 @@ class IcingIntensityNN:
...
@@ -702,8 +703,8 @@ class IcingIntensityNN:
self
.
test_false_pos
(
labels
,
pred
)
self
.
test_false_pos
(
labels
,
pred
)
def
predict
(
self
,
mini_batch
):
def
predict
(
self
,
mini_batch
):
inputs
=
[
mini_batch
[
0
]]
inputs
=
[
mini_batch
[
0
]
,
mini_batch
[
1
]
]
labels
=
mini_batch
[
1
]
labels
=
mini_batch
[
2
]
pred
=
self
.
model
(
inputs
,
training
=
False
)
pred
=
self
.
model
(
inputs
,
training
=
False
)
t_loss
=
self
.
loss
(
labels
,
pred
)
t_loss
=
self
.
loss
(
labels
,
pred
)
...
@@ -782,8 +783,8 @@ class IcingIntensityNN:
...
@@ -782,8 +783,8 @@ class IcingIntensityNN:
proc_batch_cnt
=
0
proc_batch_cnt
=
0
n_samples
=
0
n_samples
=
0
for
data0
,
label
in
self
.
train_dataset
:
for
data0
,
data1
,
label
in
self
.
train_dataset
:
trn_ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0
,
label
))
trn_ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0
,
data1
,
label
))
trn_ds
=
trn_ds
.
batch
(
BATCH_SIZE
)
trn_ds
=
trn_ds
.
batch
(
BATCH_SIZE
)
for
mini_batch
in
trn_ds
:
for
mini_batch
in
trn_ds
:
if
self
.
learningRateSchedule
is
not
None
:
if
self
.
learningRateSchedule
is
not
None
:
...
@@ -797,8 +798,8 @@ class IcingIntensityNN:
...
@@ -797,8 +798,8 @@ class IcingIntensityNN:
tf
.
summary
.
scalar
(
'
num_epochs
'
,
epoch
,
step
=
step
)
tf
.
summary
.
scalar
(
'
num_epochs
'
,
epoch
,
step
=
step
)
self
.
reset_test_metrics
()
self
.
reset_test_metrics
()
for
data0_tst
,
label_tst
in
self
.
test_dataset
:
for
data0_tst
,
data1_tst
,
label_tst
in
self
.
test_dataset
:
tst_ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0_tst
,
label_tst
))
tst_ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0_tst
,
data1_tst
,
label_tst
))
tst_ds
=
tst_ds
.
batch
(
BATCH_SIZE
)
tst_ds
=
tst_ds
.
batch
(
BATCH_SIZE
)
for
mini_batch_test
in
tst_ds
:
for
mini_batch_test
in
tst_ds
:
self
.
test_step
(
mini_batch_test
)
self
.
test_step
(
mini_batch_test
)
...
@@ -832,8 +833,8 @@ class IcingIntensityNN:
...
@@ -832,8 +833,8 @@ class IcingIntensityNN:
total_time
+=
(
t1
-
t0
)
total_time
+=
(
t1
-
t0
)
self
.
reset_test_metrics
()
self
.
reset_test_metrics
()
for
data0
,
label
in
self
.
test_dataset
:
for
data0
,
data1
,
label
in
self
.
test_dataset
:
ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0
,
label
))
ds
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
data0
,
data1
,
label
))
ds
=
ds
.
batch
(
BATCH_SIZE
)
ds
=
ds
.
batch
(
BATCH_SIZE
)
for
mini_batch
in
ds
:
for
mini_batch
in
ds
:
self
.
test_step
(
mini_batch
)
self
.
test_step
(
mini_batch
)
...
@@ -892,6 +893,7 @@ class IcingIntensityNN:
...
@@ -892,6 +893,7 @@ class IcingIntensityNN:
# flat = tf.keras.layers.concatenate([flat, flat_1d, flat_anc])
# flat = tf.keras.layers.concatenate([flat, flat_1d, flat_anc])
# flat = tf.keras.layers.concatenate([flat, flat_1d])
# flat = tf.keras.layers.concatenate([flat, flat_1d])
# self.build_dnn(flat)
# self.build_dnn(flat)
flat
=
tf
.
keras
.
layers
.
concatenate
([
flat
,
self
.
inputs
[
1
]])
self
.
build_dnn
(
flat
)
self
.
build_dnn
(
flat
)
self
.
model
=
tf
.
keras
.
Model
(
self
.
inputs
,
self
.
logits
)
self
.
model
=
tf
.
keras
.
Model
(
self
.
inputs
,
self
.
logits
)
...
...
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