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
fcd09603
Commit
fcd09603
authored
Oct 27, 2021
by
Abdullah Rashwan
Committed by
A. Unique TensorFlower
Oct 27, 2021
Browse files
Internal change
PiperOrigin-RevId: 406022769
parent
4b06b4b3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
32 deletions
+40
-32
official/vision/beta/evaluation/segmentation_metrics.py
official/vision/beta/evaluation/segmentation_metrics.py
+28
-29
official/vision/beta/tasks/semantic_segmentation.py
official/vision/beta/tasks/semantic_segmentation.py
+12
-3
No files found.
official/vision/beta/evaluation/segmentation_metrics.py
View file @
fcd09603
...
...
@@ -13,7 +13,6 @@
# limitations under the License.
"""Metrics for segmentation."""
import
tensorflow
as
tf
from
official.vision
import
keras_cv
...
...
@@ -77,11 +76,11 @@ class MeanIoU(tf.keras.metrics.MeanIoU):
if
self
.
_rescale_predictions
:
# This part can only run on cpu/gpu due to dynamic image resizing.
f
latten_
predictions
=
[]
flatten_
mask
s
=
[
]
flatten_
valid_masks
=
[]
for
mask
,
valid_mask
,
predicted_mask
,
image_info
in
zip
(
masks
,
valid_masks
,
predictions
,
images_info
):
f
or
i
in
range
(
tf
.
shape
(
predictions
)[
0
]):
mask
=
masks
[
i
]
valid_mask
=
valid_masks
[
i
]
predicted_mask
=
predictions
[
i
]
image_info
=
images_info
[
i
]
rescale_size
=
tf
.
cast
(
tf
.
math
.
ceil
(
image_info
[
1
,
:]
/
image_info
[
2
,
:]),
tf
.
int32
)
...
...
@@ -104,12 +103,12 @@ class MeanIoU(tf.keras.metrics.MeanIoU):
image_shape
[
1
])
predicted_mask
=
tf
.
argmax
(
predicted_mask
,
axis
=
2
)
flatten_predictions
.
append
(
tf
.
reshape
(
predicted_mask
,
shape
=
[
1
,
-
1
])
)
flatten_masks
.
append
(
tf
.
reshape
(
mask
,
shape
=
[
1
,
-
1
])
)
flatten_valid_masks
.
append
(
tf
.
reshape
(
valid_mask
,
shape
=
[
1
,
-
1
])
)
flatten_predictions
=
tf
.
concat
(
flatten_predictions
,
axis
=
1
)
flatten_masks
=
tf
.
concat
(
flatten_masks
,
axis
=
1
)
flatten_valid_masks
=
tf
.
c
onc
at
(
flatten_valid_masks
,
axis
=
1
)
flatten_predictions
=
tf
.
reshape
(
predicted_mask
,
shape
=
[
1
,
-
1
])
flatten_masks
=
tf
.
reshape
(
mask
,
shape
=
[
1
,
-
1
])
flatten_valid_masks
=
tf
.
reshape
(
valid_mask
,
shape
=
[
1
,
-
1
])
super
(
MeanIoU
,
self
).
update_state
(
flatten_masks
,
flatten_predictions
,
tf
.
ca
s
t
(
flatten_valid_masks
,
tf
.
float32
)
)
else
:
predictions
=
tf
.
image
.
resize
(
...
...
@@ -184,11 +183,11 @@ class PerClassIoU(keras_cv.metrics.PerClassIoU):
if
self
.
_rescale_predictions
:
# This part can only run on cpu/gpu due to dynamic image resizing.
f
latten_
predictions
=
[]
flatten_
mask
s
=
[
]
flatten_
valid_masks
=
[]
for
mask
,
valid_mask
,
predicted_mask
,
image_info
in
zip
(
masks
,
valid_masks
,
predictions
,
images_info
):
f
or
i
in
range
(
tf
.
shape
(
predictions
)[
0
]):
mask
=
masks
[
i
]
valid_mask
=
valid_masks
[
i
]
predicted_mask
=
predictions
[
i
]
image_info
=
images_info
[
i
]
rescale_size
=
tf
.
cast
(
tf
.
math
.
ceil
(
image_info
[
1
,
:]
/
image_info
[
2
,
:]),
tf
.
int32
)
...
...
@@ -211,12 +210,12 @@ class PerClassIoU(keras_cv.metrics.PerClassIoU):
image_shape
[
1
])
predicted_mask
=
tf
.
argmax
(
predicted_mask
,
axis
=
2
)
flatten_predictions
.
append
(
tf
.
reshape
(
predicted_mask
,
shape
=
[
1
,
-
1
])
)
flatten_masks
.
append
(
tf
.
reshape
(
mask
,
shape
=
[
1
,
-
1
])
)
flatten_valid_masks
.
append
(
tf
.
reshape
(
valid_mask
,
shape
=
[
1
,
-
1
])
)
flatten_predictions
=
tf
.
concat
(
flatten_predictions
,
axis
=
1
)
flatten_masks
=
tf
.
concat
(
flatten_masks
,
axis
=
1
)
flatten_valid_masks
=
tf
.
c
onc
at
(
flatten_valid_masks
,
axis
=
1
)
flatten_predictions
=
tf
.
reshape
(
predicted_mask
,
shape
=
[
1
,
-
1
])
flatten_masks
=
tf
.
reshape
(
mask
,
shape
=
[
1
,
-
1
])
flatten_valid_masks
=
tf
.
reshape
(
valid_mask
,
shape
=
[
1
,
-
1
])
super
(
PerClassIoU
,
self
).
update_state
(
flatten_masks
,
flatten_predictions
,
tf
.
ca
s
t
(
flatten_valid_masks
,
tf
.
float32
)
)
else
:
predictions
=
tf
.
image
.
resize
(
...
...
official/vision/beta/tasks/semantic_segmentation.py
View file @
fcd09603
...
...
@@ -158,6 +158,10 @@ class SemanticSegmentationTask(base_task.Task):
.
resize_eval_groundtruth
,
dtype
=
tf
.
float32
)
# Update state on CPU if TPUStrategy due to dynamic resizing.
self
.
_process_iou_metric_on_cpu
=
isinstance
(
tf
.
distribute
.
get_strategy
(),
tf
.
distribute
.
TPUStrategy
)
return
metrics
def
train_step
(
self
,
...
...
@@ -251,7 +255,11 @@ class SemanticSegmentationTask(base_task.Task):
loss
=
0
logs
=
{
self
.
loss
:
loss
}
if
self
.
_process_iou_metric_on_cpu
:
logs
.
update
({
self
.
iou_metric
.
name
:
(
labels
,
outputs
)})
else
:
self
.
iou_metric
.
update_state
(
labels
,
outputs
)
if
metrics
:
self
.
process_metrics
(
metrics
,
labels
,
outputs
)
...
...
@@ -267,6 +275,7 @@ class SemanticSegmentationTask(base_task.Task):
if
state
is
None
:
self
.
iou_metric
.
reset_states
()
state
=
self
.
iou_metric
if
self
.
_process_iou_metric_on_cpu
:
self
.
iou_metric
.
update_state
(
step_outputs
[
self
.
iou_metric
.
name
][
0
],
step_outputs
[
self
.
iou_metric
.
name
][
1
])
return
state
...
...
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