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
daf2287e
Commit
daf2287e
authored
2 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot..
parent
a8566ff6
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/srcnn_l1b_l2.py
+24
-15
24 additions, 15 deletions
modules/deeplearning/srcnn_l1b_l2.py
with
24 additions
and
15 deletions
modules/deeplearning/srcnn_l1b_l2.py
+
24
−
15
View file @
daf2287e
import
glob
import
glob
import
tensorflow
as
tf
import
tensorflow
as
tf
from
util.setup
import
logdir
,
modeldir
,
cachepath
,
now
,
ancillary_path
from
util.setup
import
logdir
,
modeldir
,
cachepath
,
now
,
ancillary_path
from
util.util
import
EarlyStop
,
normalize
,
denormalize
,
resample
,
resample_2d_linear
,
resample_one
,
resample_2d_linear_one
,
get_grid_values_all
from
util.util
import
EarlyStop
,
normalize
,
denormalize
,
resample
,
resample_2d_linear
,
resample_one
,
\
resample_2d_linear_one
,
get_grid_values_all
,
add_noise
import
os
,
datetime
import
os
,
datetime
import
numpy
as
np
import
numpy
as
np
import
pickle
import
pickle
...
@@ -29,7 +30,7 @@ TRACK_MOVING_AVERAGE = False
...
@@ -29,7 +30,7 @@ TRACK_MOVING_AVERAGE = False
EARLY_STOP
=
True
EARLY_STOP
=
True
NOISE_TRAINING
=
True
NOISE_TRAINING
=
True
NOISE_STDDEV
=
0.01
NOISE_STDDEV
=
0.
0
01
DO_AUGMENT
=
True
DO_AUGMENT
=
True
DO_ZERO_OUT
=
False
DO_ZERO_OUT
=
False
...
@@ -101,7 +102,7 @@ y_2 = y_67
...
@@ -101,7 +102,7 @@ y_2 = y_67
def
build_residual_conv2d_block
(
conv
,
num_filters
,
block_name
,
activation
=
tf
.
nn
.
relu
,
padding
=
'
SAME
'
,
def
build_residual_conv2d_block
(
conv
,
num_filters
,
block_name
,
activation
=
tf
.
nn
.
relu
,
padding
=
'
SAME
'
,
kernel_initializer
=
'
he_uniform
'
,
scale
=
None
,
kernel_size
=
3
,
kernel_initializer
=
'
he_uniform
'
,
scale
=
None
,
kernel_size
=
3
,
do_drop_out
=
True
,
drop_rate
=
0.5
,
do_batch_norm
=
Fals
e
):
do_drop_out
=
True
,
drop_rate
=
0.5
,
do_batch_norm
=
Tru
e
):
with
tf
.
name_scope
(
block_name
):
with
tf
.
name_scope
(
block_name
):
skip
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
kernel_size
,
padding
=
padding
,
kernel_initializer
=
kernel_initializer
,
activation
=
activation
)(
conv
)
skip
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
kernel_size
,
padding
=
padding
,
kernel_initializer
=
kernel_initializer
,
activation
=
activation
)(
conv
)
...
@@ -246,18 +247,18 @@ class SRCNN:
...
@@ -246,18 +247,18 @@ class SRCNN:
data_s
.
append
(
nda
)
data_s
.
append
(
nda
)
input_data
=
np
.
concatenate
(
data_s
)
input_data
=
np
.
concatenate
(
data_s
)
add_noise
=
None
DO_ADD_NOISE
=
False
noise_scale
=
None
if
is_training
and
NOISE_TRAINING
:
if
is_training
and
NOISE_TRAINING
:
add_noise
=
True
DO_ADD_NOISE
=
True
noise_scale
=
NOISE_STDDEV
data_norm
=
[]
data_norm
=
[]
for
param
in
data_params
:
for
param
in
data_params
:
idx
=
params
.
index
(
param
)
idx
=
params
.
index
(
param
)
# tmp = input_data[:, idx, slc_y_2, slc_x_2]
# tmp = input_data[:, idx, slc_y_2, slc_x_2]
tmp
=
input_data
[:,
idx
,
y_130
,
x_130
]
tmp
=
input_data
[:,
idx
,
y_130
,
x_130
]
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
,
add_noise
=
add_noise
,
noise_scale
=
noise_scale
)
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
)
if
DO_ADD_NOISE
:
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
# tmp = resample_2d_linear(x_2, y_2, tmp, t, s)
# tmp = resample_2d_linear(x_2, y_2, tmp, t, s)
data_norm
.
append
(
tmp
)
data_norm
.
append
(
tmp
)
# --------------------------
# --------------------------
...
@@ -265,15 +266,23 @@ class SRCNN:
...
@@ -265,15 +266,23 @@ class SRCNN:
idx
=
params
.
index
(
param
)
idx
=
params
.
index
(
param
)
# tmp = input_data[:, idx, slc_y_2, slc_x_2]
# tmp = input_data[:, idx, slc_y_2, slc_x_2]
tmp
=
input_data
[:,
idx
,
y_130
,
x_130
]
tmp
=
input_data
[:,
idx
,
y_130
,
x_130
]
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
,
add_noise
=
add_noise
,
noise_scale
=
noise_scale
)
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
)
if
DO_ADD_NOISE
:
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
# tmp = resample_2d_linear(x_2, y_2, tmp, t, s)
# tmp = resample_2d_linear(x_2, y_2, tmp, t, s)
data_norm
.
append
(
tmp
)
data_norm
.
append
(
tmp
)
# --------
# --------
tmp
=
input_data
[:,
label_idx
,
slc_y_2
,
slc_x_2
]
tmp
=
input_data
[:,
label_idx
,
slc_y_2
,
slc_x_2
]
if
label_param
!=
'
cloud_probability
'
:
if
label_param
!=
'
cloud_probability
'
:
tmp
=
normalize
(
tmp
,
label_param
,
mean_std_dct
,
add_noise
=
add_noise
,
noise_scale
=
noise_scale
)
tmp
=
normalize
(
tmp
,
label_param
,
mean_std_dct
)
if
DO_ADD_NOISE
:
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
else
:
else
:
if
DO_ADD_NOISE
:
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
tmp
=
np
.
where
(
tmp
<
0.0
,
0.0
,
tmp
)
tmp
=
np
.
where
(
tmp
>
1.0
,
1.0
,
tmp
)
tmp
=
resample_2d_linear
(
x_2
,
y_2
,
tmp
,
t
,
s
)
tmp
=
resample_2d_linear
(
x_2
,
y_2
,
tmp
,
t
,
s
)
data_norm
.
append
(
tmp
)
data_norm
.
append
(
tmp
)
# ---------
# ---------
...
@@ -417,8 +426,8 @@ class SRCNN:
...
@@ -417,8 +426,8 @@ class SRCNN:
conv
=
conv_b
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
3
,
kernel_initializer
=
'
he_uniform
'
,
activation
=
activation
,
padding
=
'
VALID
'
)(
input_2d
)
conv
=
conv_b
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
3
,
kernel_initializer
=
'
he_uniform
'
,
activation
=
activation
,
padding
=
'
VALID
'
)(
input_2d
)
print
(
conv
.
shape
)
print
(
conv
.
shape
)
if
NOISE_TRAINING
:
#
if NOISE_TRAINING:
conv
=
conv_b
=
tf
.
keras
.
layers
.
GaussianNoise
(
stddev
=
NOISE_STDDEV
)(
conv
)
#
conv = conv_b = tf.keras.layers.GaussianNoise(stddev=NOISE_STDDEV)(conv)
scale
=
0.2
scale
=
0.2
...
@@ -426,11 +435,11 @@ class SRCNN:
...
@@ -426,11 +435,11 @@ class SRCNN:
conv_b
=
build_residual_conv2d_block
(
conv_b
,
num_filters
,
'
Residual_Block_2
'
,
scale
=
scale
)
conv_b
=
build_residual_conv2d_block
(
conv_b
,
num_filters
,
'
Residual_Block_2
'
,
scale
=
scale
)
conv_b
=
build_residual_conv2d_block
(
conv_b
,
num_filters
,
'
Residual_Block_3
'
,
scale
=
scale
)
#
conv_b = build_residual_conv2d_block(conv_b, num_filters, 'Residual_Block_3', scale=scale)
conv_b
=
build_residual_conv2d_block
(
conv_b
,
num_filters
,
'
Residual_Block_4
'
,
scale
=
scale
)
#
conv_b = build_residual_conv2d_block(conv_b, num_filters, 'Residual_Block_4', scale=scale)
conv_b
=
build_residual_conv2d_block
(
conv_b
,
num_filters
,
'
Residual_Block_5
'
,
scale
=
scale
)
#
conv_b = build_residual_conv2d_block(conv_b, num_filters, 'Residual_Block_5', scale=scale)
conv_b
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
3
,
strides
=
1
,
activation
=
activation
,
kernel_initializer
=
'
he_uniform
'
,
padding
=
padding
)(
conv_b
)
conv_b
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
,
kernel_size
=
3
,
strides
=
1
,
activation
=
activation
,
kernel_initializer
=
'
he_uniform
'
,
padding
=
padding
)(
conv_b
)
...
...
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