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
277f935a
Unverified
Commit
277f935a
authored
Mar 20, 2022
by
srihari-humbarwadi
Browse files
import `resize_and_rescale_offsets` fn
parent
6e0d65cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
official/vision/beta/projects/panoptic_maskrcnn/ops/mask_ops.py
...al/vision/beta/projects/panoptic_maskrcnn/ops/mask_ops.py
+52
-0
No files found.
official/vision/beta/projects/panoptic_maskrcnn/ops/mask_ops.py
0 → 100644
View file @
277f935a
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utility functions for masks."""
import
tensorflow
as
tf
def
resize_and_rescale_offsets
(
input_tensor
:
tf
.
Tensor
,
target_size
):
"""Bilinearly resizes and rescales the offsets.
Args:
input_tensor: A tf.Tensor of shape [batch, height, width, 2].
target_size: A list or tuple or 1D tf.Tensor that specifies the height and
width after resizing.
reference:
https://github.com/google-research/deeplab2/blob/main/model/utils.py#L157
Returns:
The input_tensor resized to shape `[batch, target_height, target_width, 2]`.
Moreover, the offsets along the y-axis are rescaled by a factor equal to
(target_height - 1) / (reference_height - 1) and the offsets along the
x-axis are rescaled by a factor equal to
(target_width - 1) / (reference_width - 1).
"""
input_size_y
=
tf
.
shape
(
input_tensor
)[
1
]
input_size_x
=
tf
.
shape
(
input_tensor
)[
2
]
scale_y
=
tf
.
cast
(
target_size
[
0
]
-
1
,
tf
.
float32
)
/
tf
.
cast
(
input_size_y
-
1
,
tf
.
float32
)
scale_x
=
tf
.
cast
(
target_size
[
1
]
-
1
,
tf
.
float32
)
/
tf
.
cast
(
input_size_x
-
1
,
tf
.
float32
)
target_y
,
target_x
=
tf
.
split
(
value
=
input_tensor
,
num_or_size_splits
=
2
,
axis
=
3
)
target_y
*=
scale_y
target_x
*=
scale_x
target
=
tf
.
concat
([
target_y
,
target_x
],
3
)
return
tf
.
image
.
resize
(
input_tensor
,
size
=
target_size
,
method
=
tf
.
image
.
ResizeMethod
.
BILINEAR
)
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