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
7923d289
Commit
7923d289
authored
2 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
8b626a24
No related branches found
Branches containing commit
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
+30
-13
30 additions, 13 deletions
modules/deeplearning/srcnn_l1b_l2.py
with
30 additions
and
13 deletions
modules/deeplearning/srcnn_l1b_l2.py
+
30
−
13
View file @
7923d289
...
@@ -37,6 +37,7 @@ NOISE_STDDEV = 0.01
...
@@ -37,6 +37,7 @@ NOISE_STDDEV = 0.01
DO_AUGMENT
=
True
DO_AUGMENT
=
True
DO_ZERO_OUT
=
False
DO_ZERO_OUT
=
False
DO_ESPCN
=
False
# Note: If True, cannot do mixed resolution input fields (Adjust accordingly below)
# setup scaling parameters dictionary
# setup scaling parameters dictionary
mean_std_dct
=
{}
mean_std_dct
=
{}
...
@@ -98,10 +99,11 @@ elif KERNEL_SIZE == 5:
...
@@ -98,10 +99,11 @@ elif KERNEL_SIZE == 5:
y_2
=
np
.
arange
(
68
)
y_2
=
np
.
arange
(
68
)
# ----------------------------------------
# ----------------------------------------
# Exp for ESPCN version
# Exp for ESPCN version
# slc_x_2 = slice(0, 132, 2)
if
DO_ESPCN
:
# slc_y_2 = slice(0, 132, 2)
slc_x_2
=
slice
(
0
,
132
,
2
)
# x_128 = slice(2, 130)
slc_y_2
=
slice
(
0
,
132
,
2
)
# y_128 = slice(2, 130)
x_128
=
slice
(
2
,
130
)
y_128
=
slice
(
2
,
130
)
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
'
,
...
@@ -127,6 +129,13 @@ def build_residual_conv2d_block(conv, num_filters, block_name, activation=tf.nn.
...
@@ -127,6 +129,13 @@ def build_residual_conv2d_block(conv, num_filters, block_name, activation=tf.nn.
return
conv
return
conv
def
upsample
(
tmp
):
tmp
=
tmp
[:,
slc_y_2
,
slc_x_2
]
tmp
=
resample_2d_linear
(
x_2
,
y_2
,
tmp
,
t
,
s
)
tmp
=
tmp
[:,
y_k
,
x_k
]
return
tmp
class
SRCNN
:
class
SRCNN
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -259,10 +268,10 @@ class SRCNN:
...
@@ -259,10 +268,10 @@ class SRCNN:
tmp
=
tmp
.
copy
()
tmp
=
tmp
.
copy
()
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
# tmp = smooth_2d(tmp, sigma=1.0)
# tmp = smooth_2d(tmp, sigma=1.0)
# Half res upsampled to full res
:
if
DO_ESPCN
:
tmp
=
tmp
[:,
slc_y_2
,
slc_x_2
]
tmp
=
tmp
[:,
slc_y_2
,
slc_x_2
]
tmp
=
resample_2d_linear
(
x_2
,
y_2
,
tmp
,
t
,
s
)
else
:
# Half res upsampled to full res:
tmp
=
tmp
[:,
y_k
,
x_k
]
tmp
=
upsample
(
tmp
)
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
)
tmp
=
normalize
(
tmp
,
param
,
mean_std_dct
)
if
DO_ADD_NOISE
:
if
DO_ADD_NOISE
:
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
tmp
=
add_noise
(
tmp
,
noise_scale
=
NOISE_STDDEV
)
...
@@ -285,9 +294,10 @@ class SRCNN:
...
@@ -285,9 +294,10 @@ class SRCNN:
tmp
=
tmp
.
copy
()
tmp
=
tmp
.
copy
()
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
tmp
=
np
.
where
(
np
.
isnan
(
tmp
),
0
,
tmp
)
# tmp = smooth_2d(tmp, sigma=1.0)
# tmp = smooth_2d(tmp, sigma=1.0)
tmp
=
tmp
[:,
slc_y_2
,
slc_x_2
]
if
DO_ESPCN
:
tmp
=
resample_2d_linear
(
x_2
,
y_2
,
tmp
,
t
,
s
)
tmp
=
tmp
[:,
slc_y_2
,
slc_x_2
]
tmp
=
tmp
[:,
y_k
,
x_k
]
else
:
# Half res upsampled to full res:
tmp
=
upsample
(
tmp
)
if
label_param
!=
'
cloud_probability
'
:
if
label_param
!=
'
cloud_probability
'
:
tmp
=
normalize
(
tmp
,
label_param
,
mean_std_dct
)
tmp
=
normalize
(
tmp
,
label_param
,
mean_std_dct
)
if
DO_ADD_NOISE
:
if
DO_ADD_NOISE
:
...
@@ -432,9 +442,16 @@ class SRCNN:
...
@@ -432,9 +442,16 @@ class SRCNN:
conv
=
conv
+
conv_b
conv
=
conv
+
conv_b
print
(
conv
.
shape
)
print
(
conv
.
shape
)
# This is effectively a Dense layer
self
.
logits
=
tf
.
keras
.
layers
.
Conv2D
(
1
,
kernel_size
=
1
,
strides
=
1
,
padding
=
padding
,
name
=
'
regression
'
)(
conv
)
if
not
DO_ESPCN
:
# This is effectively a Dense layer
self
.
logits
=
tf
.
keras
.
layers
.
Conv2D
(
1
,
kernel_size
=
1
,
strides
=
1
,
padding
=
padding
,
name
=
'
regression
'
)(
conv
)
else
:
conv
=
tf
.
keras
.
layers
.
Conv2D
(
num_filters
*
(
factor
**
2
),
3
,
padding
=
padding
,
activation
=
activation
)(
conv
)
print
(
conv
.
shape
)
conv
=
tf
.
nn
.
depth_to_space
(
conv
,
factor
)
print
(
conv
.
shape
)
self
.
logits
=
tf
.
keras
.
layers
.
Conv2D
(
IMG_DEPTH
,
kernel_size
=
3
,
strides
=
1
,
padding
=
padding
,
name
=
'
regression
'
)(
conv
)
print
(
self
.
logits
.
shape
)
print
(
self
.
logits
.
shape
)
def
build_training
(
self
):
def
build_training
(
self
):
...
...
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