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
dfcc691c
Unverified
Commit
dfcc691c
authored
Mar 16, 2022
by
Srihari Humbarwadi
Committed by
GitHub
Mar 16, 2022
Browse files
Merge branch 'master' into panoptic-deeplab
parents
83b87f05
a9d9e633
Changes
92
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
440 additions
and
25 deletions
+440
-25
official/vision/beta/ops/augment.py
official/vision/beta/ops/augment.py
+1
-0
official/vision/beta/projects/centernet/configs/experiments/coco-centernet-hourglass-gpu.yaml
...net/configs/experiments/coco-centernet-hourglass-gpu.yaml
+4
-4
official/vision/beta/projects/centernet/configs/experiments/coco-centernet-hourglass-tpu.yaml
...net/configs/experiments/coco-centernet-hourglass-tpu.yaml
+4
-4
official/vision/beta/projects/panoptic_maskrcnn/configs/panoptic_maskrcnn.py
...a/projects/panoptic_maskrcnn/configs/panoptic_maskrcnn.py
+1
-1
official/vision/beta/projects/panoptic_maskrcnn/modeling/factory.py
...ision/beta/projects/panoptic_maskrcnn/modeling/factory.py
+1
-3
official/vision/beta/projects/panoptic_maskrcnn/modeling/panoptic_maskrcnn_model.py
...cts/panoptic_maskrcnn/modeling/panoptic_maskrcnn_model.py
+1
-1
official/vision/beta/projects/yolo/configs/yolo.py
official/vision/beta/projects/yolo/configs/yolo.py
+8
-0
official/vision/beta/projects/yolo/ops/kmeans_anchors.py
official/vision/beta/projects/yolo/ops/kmeans_anchors.py
+317
-0
official/vision/beta/projects/yolo/ops/kmeans_anchors_test.py
...cial/vision/beta/projects/yolo/ops/kmeans_anchors_test.py
+44
-0
official/vision/beta/projects/yolo/ops/loss_utils.py
official/vision/beta/projects/yolo/ops/loss_utils.py
+10
-7
official/vision/beta/projects/yolo/tasks/yolo.py
official/vision/beta/projects/yolo/tasks/yolo.py
+41
-0
official/vision/ops/augment.py
official/vision/ops/augment.py
+8
-5
No files found.
official/vision/beta/ops/augment.py
View file @
dfcc691c
...
...
@@ -1663,6 +1663,7 @@ class AutoAugment(ImageAugment):
tf_policies
=
self
.
_make_tf_policies
()
image
,
_
=
select_and_apply_random_policy
(
tf_policies
,
image
,
bboxes
=
None
)
image
=
tf
.
cast
(
image
,
dtype
=
input_image_type
)
return
image
def
distort_with_boxes
(
self
,
image
:
tf
.
Tensor
,
...
...
official/vision/beta/projects/centernet/configs/experiments/coco-centernet-hourglass-gpu.yaml
View file @
dfcc691c
...
...
@@ -38,11 +38,11 @@ task:
per_category_metrics
:
false
weight_decay
:
0.0005
gradient_clip_norm
:
10.0
annotation_file
:
'
coco/instances_val2017.json'
init_checkpoint
:
'
/placer/prod/scratch/home
/tf
-
model
-
garden
-dev
/vision/centernet/extremenet_hg104_512x512_coco17
/2021-10-19'
annotation_file
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/instances_val2017.json'
init_checkpoint
:
gs:/
/tf
_
model
_
garden/vision/centernet/extremenet_hg104_512x512_coco17
init_checkpoint_modules
:
'
backbone'
train_data
:
input_path
:
'
coco/train*'
input_path
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/train*'
drop_remainder
:
true
dtype
:
'
float16'
global_batch_size
:
64
...
...
@@ -57,7 +57,7 @@ task:
aug_rand_contrast
:
true
odapi_augmentation
:
true
validation_data
:
input_path
:
'
coco/val*'
input_path
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/val*'
drop_remainder
:
false
dtype
:
'
float16'
global_batch_size
:
16
...
...
official/vision/beta/projects/centernet/configs/experiments/coco-centernet-hourglass-tpu.yaml
View file @
dfcc691c
...
...
@@ -37,11 +37,11 @@ task:
per_category_metrics
:
false
weight_decay
:
0.0005
gradient_clip_norm
:
10.0
annotation_file
:
'
coco/instances_val2017.json'
init_checkpoint
:
'
/placer/prod/scratch/home
/tf
-
model
-
garden
-dev
/vision/centernet/extremenet_hg104_512x512_coco17
/2021-10-19'
annotation_file
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/instances_val2017.json'
init_checkpoint
:
gs:/
/tf
_
model
_
garden/vision/centernet/extremenet_hg104_512x512_coco17
init_checkpoint_modules
:
'
backbone'
train_data
:
input_path
:
'
coco/train*'
input_path
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/train*'
drop_remainder
:
true
dtype
:
'
bfloat16'
global_batch_size
:
128
...
...
@@ -56,7 +56,7 @@ task:
aug_rand_contrast
:
true
odapi_augmentation
:
true
validation_data
:
input_path
:
'
coco/val*'
input_path
:
'
/readahead/200M/placer/prod/home/tensorflow-performance-data/datasets/
coco/val*'
drop_remainder
:
false
dtype
:
'
bfloat16'
global_batch_size
:
64
...
...
official/vision/beta/projects/panoptic_maskrcnn/configs/panoptic_maskrcnn.py
View file @
dfcc691c
...
...
@@ -22,7 +22,7 @@ from official.core import config_definitions as cfg
from
official.core
import
exp_factory
from
official.modeling
import
hyperparams
from
official.modeling
import
optimization
from
official.
vision.beta.
projects.deepmac_maskrcnn.configs
import
deep_mask_head_rcnn
as
deepmac_maskrcnn
from
official.projects.deepmac_maskrcnn.configs
import
deep_mask_head_rcnn
as
deepmac_maskrcnn
from
official.vision.configs
import
common
from
official.vision.configs
import
maskrcnn
from
official.vision.configs
import
semantic_segmentation
...
...
official/vision/beta/projects/panoptic_maskrcnn/modeling/factory.py
View file @
dfcc691c
...
...
@@ -16,9 +16,7 @@
import
tensorflow
as
tf
from
official.vision.beta.projects.panoptic_maskrcnn.configs
import
panoptic_deeplab
as
panoptic_deeplab_cfg
from
official.vision.beta.projects.deepmac_maskrcnn.tasks
import
deep_mask_head_rcnn
from
official.projects.deepmac_maskrcnn.tasks
import
deep_mask_head_rcnn
from
official.vision.beta.projects.panoptic_maskrcnn.configs
import
panoptic_maskrcnn
as
panoptic_maskrcnn_cfg
from
official.vision.beta.projects.panoptic_maskrcnn.modeling
import
panoptic_deeplab_model
from
official.vision.beta.projects.panoptic_maskrcnn.modeling.heads
import
panoptic_deeplab_heads
...
...
official/vision/beta/projects/panoptic_maskrcnn/modeling/panoptic_maskrcnn_model.py
View file @
dfcc691c
...
...
@@ -18,7 +18,7 @@ from typing import List, Mapping, Optional, Union
import
tensorflow
as
tf
from
official.
vision.beta.
projects.deepmac_maskrcnn.modeling
import
maskrcnn_model
from
official.projects.deepmac_maskrcnn.modeling
import
maskrcnn_model
class
PanopticMaskRCNNModel
(
maskrcnn_model
.
DeepMaskRCNNModel
):
...
...
official/vision/beta/projects/yolo/configs/yolo.py
View file @
dfcc691c
...
...
@@ -187,6 +187,11 @@ class AnchorBoxes(hyperparams.Config):
level_limits
:
Optional
[
List
[
int
]]
=
None
anchors_per_scale
:
int
=
3
generate_anchors
:
bool
=
False
scaling_mode
:
str
=
'sqrt'
box_generation_mode
:
str
=
'per_level'
num_samples
:
int
=
1024
def
get
(
self
,
min_level
,
max_level
):
"""Distribute them in order to each level.
...
...
@@ -211,6 +216,9 @@ class AnchorBoxes(hyperparams.Config):
start
+=
self
.
anchors_per_scale
return
anchors_per_level
,
self
.
level_limits
def
set_boxes
(
self
,
boxes
):
self
.
boxes
=
[
Box
(
box
=
box
)
for
box
in
boxes
]
@
dataclasses
.
dataclass
class
Yolo
(
hyperparams
.
Config
):
...
...
official/vision/beta/projects/yolo/ops/kmeans_anchors.py
0 → 100644
View file @
dfcc691c
This diff is collapsed.
Click to expand it.
official/vision/beta/projects/yolo/ops/kmeans_anchors_test.py
0 → 100644
View file @
dfcc691c
# 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.
"""kmeans_test tests."""
from
absl.testing
import
parameterized
import
numpy
as
np
import
tensorflow
as
tf
from
official.vision.beta.projects.yolo.ops
import
kmeans_anchors
class
KMeansTest
(
parameterized
.
TestCase
,
tf
.
test
.
TestCase
):
@
parameterized
.
parameters
((
9
,
3
,
100
))
def
test_kmeans
(
self
,
k
,
anchors_per_scale
,
samples
):
sample_list
=
[]
for
_
in
range
(
samples
):
boxes
=
tf
.
convert_to_tensor
(
np
.
random
.
uniform
(
0
,
1
,
[
k
*
100
,
4
]))
sample_list
.
append
({
"groundtruth_boxes"
:
boxes
,
"width"
:
10
,
"height"
:
10
})
kmeans
=
kmeans_anchors
.
AnchorKMeans
()
cl
=
kmeans
(
sample_list
,
k
,
anchors_per_scale
,
image_resolution
=
[
512
,
512
,
3
])
cl
=
tf
.
convert_to_tensor
(
cl
)
self
.
assertAllEqual
(
tf
.
shape
(
cl
).
numpy
(),
[
k
,
2
])
if
__name__
==
"__main__"
:
tf
.
test
.
main
()
official/vision/beta/projects/yolo/ops/loss_utils.py
View file @
dfcc691c
...
...
@@ -176,40 +176,43 @@ class GridGenerator:
self
.
_anchors
=
tf
.
convert_to_tensor
(
anchors
)
return
def
_build_grid_points
(
self
,
l
width
,
lheight
,
anchors
,
dtype
):
def
_build_grid_points
(
self
,
l
height
,
lwidth
,
anchors
,
dtype
):
"""Generate a grid of fixed grid edges for box center decoding."""
with
tf
.
name_scope
(
'center_grid'
):
y
=
tf
.
range
(
0
,
lheight
)
x
=
tf
.
range
(
0
,
lwidth
)
num
=
tf
.
shape
(
anchors
)[
0
]
x_left
=
tf
.
tile
(
tf
.
transpose
(
tf
.
expand_dims
(
y
,
axis
=-
1
),
perm
=
[
1
,
0
]),
[
l
width
,
1
])
y_left
=
tf
.
tile
(
tf
.
expand_dims
(
x
,
axis
=-
1
),
[
1
,
l
height
])
tf
.
transpose
(
tf
.
expand_dims
(
x
,
axis
=-
1
),
perm
=
[
1
,
0
]),
[
l
height
,
1
])
y_left
=
tf
.
tile
(
tf
.
expand_dims
(
y
,
axis
=-
1
),
[
1
,
l
width
])
x_y
=
tf
.
stack
([
x_left
,
y_left
],
axis
=-
1
)
x_y
=
tf
.
cast
(
x_y
,
dtype
=
dtype
)
num
=
tf
.
shape
(
anchors
)[
0
]
x_y
=
tf
.
expand_dims
(
tf
.
tile
(
tf
.
expand_dims
(
x_y
,
axis
=-
2
),
[
1
,
1
,
num
,
1
]),
axis
=
0
)
return
x_y
def
_build_anchor_grid
(
self
,
anchors
,
dtype
):
def
_build_anchor_grid
(
self
,
height
,
width
,
anchors
,
dtype
):
"""Get the transformed anchor boxes for each dimention."""
with
tf
.
name_scope
(
'anchor_grid'
):
num
=
tf
.
shape
(
anchors
)[
0
]
anchors
=
tf
.
cast
(
anchors
,
dtype
=
dtype
)
anchors
=
tf
.
reshape
(
anchors
,
[
1
,
1
,
1
,
num
,
2
])
anchors
=
tf
.
tile
(
anchors
,
[
1
,
tf
.
cast
(
height
,
tf
.
int32
),
tf
.
cast
(
width
,
tf
.
int32
),
1
,
1
])
return
anchors
def
_extend_batch
(
self
,
grid
,
batch_size
):
return
tf
.
tile
(
grid
,
[
batch_size
,
1
,
1
,
1
,
1
])
def
__call__
(
self
,
width
,
height
,
batch_size
,
dtype
=
None
):
def
__call__
(
self
,
height
,
width
,
batch_size
,
dtype
=
None
):
if
dtype
is
None
:
self
.
dtype
=
tf
.
keras
.
backend
.
floatx
()
else
:
self
.
dtype
=
dtype
grid_points
=
self
.
_build_grid_points
(
width
,
height
,
self
.
_anchors
,
grid_points
=
self
.
_build_grid_points
(
height
,
width
,
self
.
_anchors
,
self
.
dtype
)
anchor_grid
=
self
.
_build_anchor_grid
(
height
,
width
,
tf
.
cast
(
self
.
_anchors
,
self
.
dtype
)
/
tf
.
cast
(
self
.
_scale_anchors
,
self
.
dtype
),
self
.
dtype
)
...
...
official/vision/beta/projects/yolo/tasks/yolo.py
View file @
dfcc691c
This diff is collapsed.
Click to expand it.
official/vision/ops/augment.py
View file @
dfcc691c
...
...
@@ -1663,6 +1663,7 @@ class AutoAugment(ImageAugment):
tf_policies
=
self
.
_make_tf_policies
()
image
,
_
=
select_and_apply_random_policy
(
tf_policies
,
image
,
bboxes
=
None
)
image
=
tf
.
cast
(
image
,
dtype
=
input_image_type
)
return
image
def
distort_with_boxes
(
self
,
image
:
tf
.
Tensor
,
...
...
@@ -2259,7 +2260,7 @@ class MixupAndCutmix:
labels
:
tf
.
Tensor
)
->
Tuple
[
tf
.
Tensor
,
tf
.
Tensor
,
tf
.
Tensor
]:
"""Apply cutmix."""
lam
=
MixupAndCutmix
.
_sample_from_beta
(
self
.
cutmix_alpha
,
self
.
cutmix_alpha
,
labels
.
shape
)
tf
.
shape
(
labels
)
)
ratio
=
tf
.
math
.
sqrt
(
1
-
lam
)
...
...
@@ -2284,17 +2285,19 @@ class MixupAndCutmix:
lambda
x
:
_fill_rectangle
(
*
x
),
(
images
,
random_center_width
,
random_center_height
,
cut_width
//
2
,
cut_height
//
2
,
tf
.
reverse
(
images
,
[
0
])),
dtype
=
(
tf
.
float32
,
tf
.
int32
,
tf
.
int32
,
tf
.
int32
,
tf
.
int32
,
tf
.
float32
),
fn_output_signature
=
tf
.
TensorSpec
(
images
.
shape
[
1
:],
dtype
=
tf
.
float32
))
dtype
=
(
images
.
dtype
,
tf
.
int32
,
tf
.
int32
,
tf
.
int32
,
tf
.
int32
,
images
.
dtype
),
fn_output_signature
=
tf
.
TensorSpec
(
images
.
shape
[
1
:],
dtype
=
images
.
dtype
))
return
images
,
labels
,
lam
def
_mixup
(
self
,
images
:
tf
.
Tensor
,
labels
:
tf
.
Tensor
)
->
Tuple
[
tf
.
Tensor
,
tf
.
Tensor
,
tf
.
Tensor
]:
lam
=
MixupAndCutmix
.
_sample_from_beta
(
self
.
mixup_alpha
,
self
.
mixup_alpha
,
labels
.
shape
)
tf
.
shape
(
labels
)
)
lam
=
tf
.
reshape
(
lam
,
[
-
1
,
1
,
1
,
1
])
images
=
lam
*
images
+
(
1.
-
lam
)
*
tf
.
reverse
(
images
,
[
0
])
lam_cast
=
tf
.
cast
(
lam
,
dtype
=
images
.
dtype
)
images
=
lam_cast
*
images
+
(
1.
-
lam_cast
)
*
tf
.
reverse
(
images
,
[
0
])
return
images
,
labels
,
tf
.
squeeze
(
lam
)
...
...
Prev
1
2
3
4
5
Next
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