tf-models-nightly 2.18.0.dev20240820__py2.py3-none-any.whl → 2.18.0.dev20240821__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- official/legacy/transformer/transformer_main.py +0 -2
- official/projects/maskconver/__init__.py +14 -0
- official/projects/maskconver/configs/__init__.py +14 -0
- official/projects/maskconver/configs/backbones.py +43 -0
- official/projects/maskconver/configs/decoders.py +36 -0
- official/projects/maskconver/configs/maskconver.py +523 -0
- official/projects/maskconver/configs/multiscale_maskconver.py +215 -0
- official/projects/maskconver/tasks/__init__.py +14 -0
- official/projects/maskconver/tasks/maskconver.py +641 -0
- official/projects/maskconver/tasks/multiscale_maskconver.py +278 -0
- official/projects/maskconver/train.py +30 -0
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/METADATA +1 -1
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/RECORD +17 -7
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/AUTHORS +0 -0
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/LICENSE +0 -0
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/WHEEL +0 -0
- {tf_models_nightly-2.18.0.dev20240820.dist-info → tf_models_nightly-2.18.0.dev20240821.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""Multi-scale Maskconver configuration definition."""
|
16
|
+
|
17
|
+
import dataclasses
|
18
|
+
import os
|
19
|
+
from typing import List, Optional
|
20
|
+
|
21
|
+
from official.core import config_definitions as cfg
|
22
|
+
from official.core import exp_factory
|
23
|
+
from official.modeling import hyperparams
|
24
|
+
from official.modeling import optimization
|
25
|
+
from official.projects.maskconver.configs import maskconver
|
26
|
+
from official.vision.configs import common
|
27
|
+
|
28
|
+
# pylint: disable=unused-private-name
|
29
|
+
# pytype: disable=wrong-keyword-args
|
30
|
+
# pylint: disable=unexpected-keyword-arg
|
31
|
+
|
32
|
+
_COCO_INPUT_PATH_BASE = 'coco/tfrecords'
|
33
|
+
_COCO_TRAIN_EXAMPLES = 118287
|
34
|
+
_COCO_VAL_EXAMPLES = 5000
|
35
|
+
|
36
|
+
TfExampleDecoder = maskconver.TfExampleDecoder
|
37
|
+
DataDecoder = maskconver.DataDecoder
|
38
|
+
DataConfig = maskconver.DataConfig
|
39
|
+
Losses = maskconver.Losses
|
40
|
+
PanopticGenerator = maskconver.PanopticGenerator
|
41
|
+
PanopticQualityEvaluator = maskconver.PanopticQualityEvaluator
|
42
|
+
|
43
|
+
|
44
|
+
@dataclasses.dataclass
|
45
|
+
class CopyPaste(hyperparams.Config):
|
46
|
+
copypaste_frequency: float = 1.0
|
47
|
+
aug_scale_min: float = 0.1
|
48
|
+
aug_scale_max: float = 1.9
|
49
|
+
copypaste_aug_scale_max: float = 1.0
|
50
|
+
copypaste_aug_scale_min: float = 0.05
|
51
|
+
|
52
|
+
|
53
|
+
@dataclasses.dataclass
|
54
|
+
class Parser(hyperparams.Config):
|
55
|
+
"""MaskConver parser config."""
|
56
|
+
aug_rand_hflip: bool = False
|
57
|
+
aug_scale_min: float = 1.0
|
58
|
+
aug_scale_max: float = 1.0
|
59
|
+
# If segmentation_resize_eval_groundtruth is set to False, original image
|
60
|
+
# sizes are used for eval. In that case,
|
61
|
+
# segmentation_groundtruth_padded_size has to be specified too to allow for
|
62
|
+
# batching the variable input sizes of images.
|
63
|
+
segmentation_resize_eval_groundtruth: bool = True
|
64
|
+
segmentation_groundtruth_padded_size: List[int] = dataclasses.field(
|
65
|
+
default_factory=list)
|
66
|
+
segmentation_ignore_label: int = 0
|
67
|
+
panoptic_ignore_label: int = 0
|
68
|
+
# Setting this to true will enable parsing category_mask and instance_mask.
|
69
|
+
include_panoptic_masks: bool = True
|
70
|
+
gaussaian_iou: float = 0.7
|
71
|
+
max_num_instances: int = 256
|
72
|
+
aug_type: common.Augmentation = dataclasses.field(
|
73
|
+
default_factory=common.Augmentation)
|
74
|
+
fpn_low_range: List[int] = dataclasses.field(default_factory=list)
|
75
|
+
fpn_high_range: List[int] = dataclasses.field(default_factory=list)
|
76
|
+
mask_target_level: int = 1
|
77
|
+
copypaste: CopyPaste = dataclasses.field(default_factory=CopyPaste)
|
78
|
+
|
79
|
+
|
80
|
+
@dataclasses.dataclass
|
81
|
+
class MultiScaleMaskConverHead(hyperparams.Config):
|
82
|
+
"""Segmentation head config."""
|
83
|
+
num_convs: int = 4
|
84
|
+
num_filters: int = 256
|
85
|
+
use_depthwise_convolution: bool = False
|
86
|
+
prediction_kernel_size: int = 3
|
87
|
+
upsample_factor: int = 1
|
88
|
+
depthwise_kernel_size: int = 7
|
89
|
+
use_layer_norm: bool = True
|
90
|
+
|
91
|
+
|
92
|
+
@dataclasses.dataclass
|
93
|
+
class MultiScaleMaskConver(maskconver.MaskConver):
|
94
|
+
"""Multi-scale MaskConver model config."""
|
95
|
+
min_level: int = 3
|
96
|
+
max_level: int = 7
|
97
|
+
num_instances: int = 100
|
98
|
+
class_head: MultiScaleMaskConverHead = dataclasses.field(
|
99
|
+
default_factory=MultiScaleMaskConverHead
|
100
|
+
)
|
101
|
+
mask_embedding_head: MultiScaleMaskConverHead = dataclasses.field(
|
102
|
+
default_factory=MultiScaleMaskConverHead
|
103
|
+
)
|
104
|
+
per_pixel_embedding_head: maskconver.SegmentationHead = dataclasses.field(
|
105
|
+
default_factory=lambda: maskconver.SegmentationHead(use_layer_norm=True)
|
106
|
+
)
|
107
|
+
|
108
|
+
|
109
|
+
###################################
|
110
|
+
###### PANOPTIC SEGMENTATION ######
|
111
|
+
###################################
|
112
|
+
|
113
|
+
|
114
|
+
@dataclasses.dataclass
|
115
|
+
class MultiScaleMaskConverTask(cfg.TaskConfig):
|
116
|
+
"""MaskConverTask task config."""
|
117
|
+
model: MultiScaleMaskConver = dataclasses.field(
|
118
|
+
default_factory=MultiScaleMaskConver
|
119
|
+
)
|
120
|
+
train_data: DataConfig = dataclasses.field(
|
121
|
+
default_factory=lambda: DataConfig(is_training=True)
|
122
|
+
)
|
123
|
+
# pylint: disable=g-long-lambda
|
124
|
+
validation_data: DataConfig = dataclasses.field(
|
125
|
+
default_factory=lambda: DataConfig(
|
126
|
+
is_training=False, drop_remainder=False
|
127
|
+
)
|
128
|
+
)
|
129
|
+
# pylint: enable=g-long-lambda
|
130
|
+
losses: Losses = dataclasses.field(default_factory=Losses)
|
131
|
+
init_checkpoint: Optional[str] = None
|
132
|
+
|
133
|
+
init_checkpoint_modules: Optional[List[str]] = dataclasses.field(
|
134
|
+
default_factory=list)
|
135
|
+
panoptic_quality_evaluator: PanopticQualityEvaluator = dataclasses.field(
|
136
|
+
default_factory=PanopticQualityEvaluator
|
137
|
+
)
|
138
|
+
|
139
|
+
|
140
|
+
@exp_factory.register_config_factory('multiscale_maskconver_coco')
|
141
|
+
def multiscale_maskconver_coco() -> cfg.ExperimentConfig:
|
142
|
+
"""COCO panoptic segmentation with MaskConver."""
|
143
|
+
train_batch_size = 128
|
144
|
+
eval_batch_size = 1
|
145
|
+
validation_steps = _COCO_VAL_EXAMPLES // eval_batch_size
|
146
|
+
|
147
|
+
# coco panoptic dataset has category ids ranging from [0-200] inclusive.
|
148
|
+
# 0 is not used and represents the background class
|
149
|
+
# ids 1-91 represent thing categories (91)
|
150
|
+
# ids 92-200 represent stuff categories (109)
|
151
|
+
# for the segmentation task, we continue using id=0 for the background
|
152
|
+
# and map all thing categories to id=1, the remaining 109 stuff categories
|
153
|
+
# are shifted by an offset=90 given by num_thing classes - 1. This shifting
|
154
|
+
# will make all the stuff categories begin from id=2 and end at id=110
|
155
|
+
num_panoptic_categories = 201
|
156
|
+
num_thing_categories = 91
|
157
|
+
# num_semantic_segmentation_classes = 111
|
158
|
+
|
159
|
+
is_thing = [False]
|
160
|
+
for idx in range(1, num_panoptic_categories):
|
161
|
+
is_thing.append(True if idx < num_thing_categories else False)
|
162
|
+
|
163
|
+
config = cfg.ExperimentConfig(
|
164
|
+
runtime=cfg.RuntimeConfig(
|
165
|
+
mixed_precision_dtype='float32', enable_xla=False),
|
166
|
+
task=MultiScaleMaskConverTask(
|
167
|
+
init_checkpoint='gs://cloud-tpu-checkpoints/vision-2.0/resnet50_imagenet/ckpt-28080', # pylint: disable=line-too-long
|
168
|
+
init_checkpoint_modules=['backbone'],
|
169
|
+
model=MultiScaleMaskConver(
|
170
|
+
num_classes=201,
|
171
|
+
num_thing_classes=91,
|
172
|
+
input_size=[640, 640, 3],
|
173
|
+
padded_output_size=[640, 640]),
|
174
|
+
losses=Losses(l2_weight_decay=1e-4),
|
175
|
+
train_data=DataConfig(
|
176
|
+
input_path=os.path.join(_COCO_INPUT_PATH_BASE, 'train*'),
|
177
|
+
is_training=True,
|
178
|
+
global_batch_size=train_batch_size,
|
179
|
+
parser=Parser(
|
180
|
+
aug_rand_hflip=True,
|
181
|
+
aug_scale_min=0.1,
|
182
|
+
aug_scale_max=1.9,
|
183
|
+
fpn_low_range=[0, 40, 80, 160, 320],
|
184
|
+
fpn_high_range=[64, 128, 256, 512, 10000000],
|
185
|
+
aug_type=common.Augmentation(
|
186
|
+
type='autoaug',
|
187
|
+
autoaug=common.AutoAugment(
|
188
|
+
augmentation_name='panoptic_deeplab_policy')))),
|
189
|
+
validation_data=DataConfig(
|
190
|
+
input_path=os.path.join(_COCO_INPUT_PATH_BASE, 'val*'),
|
191
|
+
is_training=False,
|
192
|
+
global_batch_size=eval_batch_size,
|
193
|
+
parser=Parser(
|
194
|
+
segmentation_resize_eval_groundtruth=False,
|
195
|
+
segmentation_groundtruth_padded_size=[640, 640]),
|
196
|
+
drop_remainder=False),
|
197
|
+
panoptic_quality_evaluator=PanopticQualityEvaluator(
|
198
|
+
num_categories=num_panoptic_categories,
|
199
|
+
ignored_label=0,
|
200
|
+
is_thing=is_thing,
|
201
|
+
rescale_predictions=True)),
|
202
|
+
trainer=cfg.TrainerConfig(
|
203
|
+
train_steps=200000,
|
204
|
+
validation_steps=validation_steps,
|
205
|
+
validation_interval=1000,
|
206
|
+
steps_per_loop=1000,
|
207
|
+
summary_interval=1000,
|
208
|
+
checkpoint_interval=1000,
|
209
|
+
optimizer_config=optimization.OptimizationConfig()),
|
210
|
+
restrictions=[
|
211
|
+
'task.train_data.is_training != None',
|
212
|
+
'task.validation_data.is_training != None'
|
213
|
+
])
|
214
|
+
return config
|
215
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|