Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
cbe77ec0
Commit
cbe77ec0
authored
Jul 01, 2021
by
Dan Kondratyuk
Committed by
A. Unique TensorFlower
Jul 01, 2021
Browse files
Revert causal padding until new checkpoints are trained.
PiperOrigin-RevId: 382606601
parent
c3b4fa95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
official/vision/beta/modeling/layers/nn_layers.py
official/vision/beta/modeling/layers/nn_layers.py
+14
-5
official/vision/beta/modeling/layers/nn_layers_test.py
official/vision/beta/modeling/layers/nn_layers_test.py
+4
-0
No files found.
official/vision/beta/modeling/layers/nn_layers.py
View file @
cbe77ec0
...
@@ -26,6 +26,10 @@ from official.modeling import tf_utils
...
@@ -26,6 +26,10 @@ from official.modeling import tf_utils
States
=
Dict
[
str
,
tf
.
Tensor
]
States
=
Dict
[
str
,
tf
.
Tensor
]
Activation
=
Union
[
str
,
Callable
]
Activation
=
Union
[
str
,
Callable
]
# TODO(dankondratyuk): keep legacy padding until new checkpoints are trained.
# Otherwise, accuracy will be affected.
LEGACY_PADDING
=
True
def
make_divisible
(
value
:
float
,
def
make_divisible
(
value
:
float
,
divisor
:
int
,
divisor
:
int
,
...
@@ -725,7 +729,8 @@ class CausalConvMixin:
...
@@ -725,7 +729,8 @@ class CausalConvMixin:
def
_compute_buffered_causal_padding
(
self
,
def
_compute_buffered_causal_padding
(
self
,
inputs
:
tf
.
Tensor
,
inputs
:
tf
.
Tensor
,
use_buffered_input
:
bool
=
False
,
use_buffered_input
:
bool
=
False
,
time_axis
:
int
=
1
)
->
List
[
List
[
int
]]:
time_axis
:
int
=
1
,
)
->
List
[
List
[
int
]]:
"""Calculates padding for 'causal' option for conv layers.
"""Calculates padding for 'causal' option for conv layers.
Args:
Args:
...
@@ -747,10 +752,14 @@ class CausalConvMixin:
...
@@ -747,10 +752,14 @@ class CausalConvMixin:
(
self
.
kernel_size
[
i
]
-
1
)
*
(
self
.
dilation_rate
[
i
]
-
1
))
(
self
.
kernel_size
[
i
]
-
1
)
*
(
self
.
dilation_rate
[
i
]
-
1
))
for
i
in
range
(
self
.
rank
)
for
i
in
range
(
self
.
rank
)
]
]
pad_total
=
[
kernel_size_effective
[
0
]
-
1
]
if
LEGACY_PADDING
:
for
i
in
range
(
1
,
self
.
rank
):
# Apply legacy padding that does not take into account spatial strides
overlap
=
(
input_shape
[
i
]
-
1
)
%
self
.
strides
[
i
]
+
1
pad_total
=
[
kernel_size_effective
[
i
]
-
1
for
i
in
range
(
self
.
rank
)]
pad_total
.
append
(
tf
.
maximum
(
kernel_size_effective
[
i
]
-
overlap
,
0
))
else
:
pad_total
=
[
kernel_size_effective
[
0
]
-
1
]
for
i
in
range
(
1
,
self
.
rank
):
overlap
=
(
input_shape
[
i
]
-
1
)
%
self
.
strides
[
i
]
+
1
pad_total
.
append
(
tf
.
maximum
(
kernel_size_effective
[
i
]
-
overlap
,
0
))
pad_beg
=
[
pad_total
[
i
]
//
2
for
i
in
range
(
self
.
rank
)]
pad_beg
=
[
pad_total
[
i
]
//
2
for
i
in
range
(
self
.
rank
)]
pad_end
=
[
pad_total
[
i
]
-
pad_beg
[
i
]
for
i
in
range
(
self
.
rank
)]
pad_end
=
[
pad_total
[
i
]
-
pad_beg
[
i
]
for
i
in
range
(
self
.
rank
)]
padding
=
[[
pad_beg
[
i
],
pad_end
[
i
]]
for
i
in
range
(
self
.
rank
)]
padding
=
[[
pad_beg
[
i
],
pad_end
[
i
]]
for
i
in
range
(
self
.
rank
)]
...
...
official/vision/beta/modeling/layers/nn_layers_test.py
View file @
cbe77ec0
...
@@ -24,6 +24,10 @@ from official.vision.beta.modeling.layers import nn_layers
...
@@ -24,6 +24,10 @@ from official.vision.beta.modeling.layers import nn_layers
class
NNLayersTest
(
parameterized
.
TestCase
,
tf
.
test
.
TestCase
):
class
NNLayersTest
(
parameterized
.
TestCase
,
tf
.
test
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
nn_layers
.
LEGACY_PADDING
=
False
def
test_hard_swish
(
self
):
def
test_hard_swish
(
self
):
activation
=
tf
.
keras
.
layers
.
Activation
(
'hard_swish'
)
activation
=
tf
.
keras
.
layers
.
Activation
(
'hard_swish'
)
output
=
activation
(
tf
.
constant
([
-
3
,
-
1.5
,
0
,
3
]))
output
=
activation
(
tf
.
constant
([
-
3
,
-
1.5
,
0
,
3
]))
...
...
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