Skip to content

Commit 34f03db

Browse files
hawkinsptensorflower-gardener
authored andcommitted
No public description
PiperOrigin-RevId: 658525407
1 parent afb8651 commit 34f03db

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

official/projects/mosaic/configs/mosaic_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
"""Configuration definition for Semantic Segmentation with MOSAIC."""
1616
import dataclasses
17+
import math
1718
import os
1819
from typing import List, Optional, Union
1920

20-
import numpy as np
21-
2221
from official.core import config_definitions as cfg
2322
from official.core import exp_factory
2423
from official.modeling import hyperparams
@@ -133,7 +132,7 @@ def mosaic_mnv35_cityscapes() -> cfg.ExperimentConfig:
133132
steps_per_epoch = CITYSCAPES_TRAIN_EXAMPLES // train_batch_size
134133
output_stride = 16
135134

136-
backbone_output_level = int(np.math.log2(output_stride))
135+
backbone_output_level = int(math.log2(output_stride))
137136
config = cfg.ExperimentConfig(
138137
task=MosaicSemanticSegmentationTask(
139138
model=MosaicSemanticSegmentationModel(

official/projects/panoptic/configs/panoptic_deeplab.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
"""Panoptic Deeplab configuration definition."""
1616
import dataclasses
17+
import math
1718
import os
1819
from typing import List, Optional, Union
1920

20-
import numpy as np
21-
2221
from official.core import config_definitions as cfg
2322
from official.core import exp_factory
2423
from official.modeling import hyperparams
@@ -220,7 +219,7 @@ def panoptic_deeplab_resnet_coco() -> cfg.ExperimentConfig:
220219
aspp_dilation_rates = [6, 12, 18]
221220
multigrid = [1, 2, 4]
222221
stem_type = 'v1'
223-
level = int(np.math.log2(output_stride))
222+
level = int(math.log2(output_stride))
224223

225224
config = cfg.ExperimentConfig(
226225
runtime=cfg.RuntimeConfig(
@@ -385,7 +384,7 @@ def panoptic_deeplab_mobilenetv3_large_coco() -> cfg.ExperimentConfig:
385384
input_size = [640, 640, 3]
386385
output_stride = 16
387386
aspp_dilation_rates = [6, 12, 18]
388-
level = int(np.math.log2(output_stride))
387+
level = int(math.log2(output_stride))
389388

390389
config = cfg.ExperimentConfig(
391390
runtime=cfg.RuntimeConfig(
@@ -547,7 +546,7 @@ def panoptic_deeplab_mobilenetv3_small_coco() -> cfg.ExperimentConfig:
547546
input_size = [640, 640, 3]
548547
output_stride = 16
549548
aspp_dilation_rates = [6, 12, 18]
550-
level = int(np.math.log2(output_stride))
549+
level = int(math.log2(output_stride))
551550

552551
config = cfg.ExperimentConfig(
553552
runtime=cfg.RuntimeConfig(

official/vision/configs/semantic_segmentation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
"""Semantic segmentation configuration definition."""
1616
import dataclasses
17+
import math
1718
import os
1819
from typing import List, Optional, Sequence, Union
1920

20-
import numpy as np
21-
2221
from official.core import config_definitions as cfg
2322
from official.core import exp_factory
2423
from official.modeling import hyperparams
@@ -233,7 +232,7 @@ def seg_deeplabv3_pascal() -> cfg.ExperimentConfig:
233232
aspp_dilation_rates = [12, 24, 36] # [6, 12, 18] if output_stride = 16
234233
multigrid = [1, 2, 4]
235234
stem_type = 'v1'
236-
level = int(np.math.log2(output_stride))
235+
level = int(math.log2(output_stride))
237236
config = cfg.ExperimentConfig(
238237
task=SemanticSegmentationTask(
239238
model=SemanticSegmentationModel(
@@ -325,7 +324,7 @@ def seg_deeplabv3plus_pascal() -> cfg.ExperimentConfig:
325324
aspp_dilation_rates = [6, 12, 18]
326325
multigrid = [1, 2, 4]
327326
stem_type = 'v1'
328-
level = int(np.math.log2(output_stride))
327+
level = int(math.log2(output_stride))
329328
config = cfg.ExperimentConfig(
330329
task=SemanticSegmentationTask(
331330
model=SemanticSegmentationModel(
@@ -492,7 +491,7 @@ def mnv2_deeplabv3_pascal() -> cfg.ExperimentConfig:
492491
steps_per_epoch = PASCAL_TRAIN_EXAMPLES // train_batch_size
493492
output_stride = 16
494493
aspp_dilation_rates = []
495-
level = int(np.math.log2(output_stride))
494+
level = int(math.log2(output_stride))
496495
pool_kernel_size = []
497496

498497
config = cfg.ExperimentConfig(
@@ -593,7 +592,7 @@ def seg_deeplabv3plus_cityscapes() -> cfg.ExperimentConfig:
593592
aspp_dilation_rates = [6, 12, 18]
594593
multigrid = [1, 2, 4]
595594
stem_type = 'v1'
596-
level = int(np.math.log2(output_stride))
595+
level = int(math.log2(output_stride))
597596
config = cfg.ExperimentConfig(
598597
task=SemanticSegmentationTask(
599598
model=SemanticSegmentationModel(
@@ -694,7 +693,7 @@ def mnv2_deeplabv3_cityscapes() -> cfg.ExperimentConfig:
694693
aspp_dilation_rates = []
695694
pool_kernel_size = [512, 1024]
696695

697-
level = int(np.math.log2(output_stride))
696+
level = int(math.log2(output_stride))
698697
config = cfg.ExperimentConfig(
699698
task=SemanticSegmentationTask(
700699
model=SemanticSegmentationModel(

official/vision/modeling/backbones/resnet_deeplab.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
"""Contains definitions of Residual Networks with Deeplab modifications."""
1616

17-
from typing import Callable, Optional, Tuple, List
17+
import math
18+
from typing import Callable, List, Optional, Tuple
1819

19-
import numpy as np
2020
import tensorflow as tf, tf_keras
21+
2122
from official.modeling import hyperparams
2223
from official.modeling import tf_utils
2324
from official.vision.modeling.backbones import factory
@@ -238,7 +239,7 @@ def __init__(
238239
else:
239240
x = layers.MaxPool2D(pool_size=3, strides=2, padding='same')(x)
240241

241-
normal_resnet_stage = int(np.math.log2(self._output_stride)) - 2
242+
normal_resnet_stage = int(math.log2(self._output_stride)) - 2
242243

243244
endpoints = {}
244245
for i in range(normal_resnet_stage + 1):

official/vision/modeling/backbones/resnet_deeplab_test.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
"""Tests for resnet_deeplab models."""
1616

17+
import math
18+
1719
# Import libraries
20+
1821
from absl.testing import parameterized
1922
import numpy as np
2023
import tensorflow as tf, tf_keras
@@ -46,10 +49,15 @@ def test_network_creation(self, input_size, model_id,
4649
inputs = tf_keras.Input(shape=(input_size, input_size, 3), batch_size=1)
4750
endpoints = network(inputs)
4851
print(endpoints)
49-
self.assertAllEqual([
50-
1, input_size / output_stride, input_size / output_stride,
51-
512 * endpoint_filter_scale
52-
], endpoints[str(int(np.math.log2(output_stride)))].shape.as_list())
52+
self.assertAllEqual(
53+
[
54+
1,
55+
input_size / output_stride,
56+
input_size / output_stride,
57+
512 * endpoint_filter_scale,
58+
],
59+
endpoints[str(int(math.log2(output_stride)))].shape.as_list(),
60+
)
5361

5462
@parameterized.parameters(
5563
('v0', None, 0.0, False, False),
@@ -82,10 +90,15 @@ def test_network_features(self, stem_type, se_ratio,
8290
inputs = tf_keras.Input(shape=(input_size, input_size, 3), batch_size=1)
8391
endpoints = network(inputs)
8492
print(endpoints)
85-
self.assertAllEqual([
86-
1, input_size / output_stride, input_size / output_stride,
87-
512 * endpoint_filter_scale
88-
], endpoints[str(int(np.math.log2(output_stride)))].shape.as_list())
93+
self.assertAllEqual(
94+
[
95+
1,
96+
input_size / output_stride,
97+
input_size / output_stride,
98+
512 * endpoint_filter_scale,
99+
],
100+
endpoints[str(int(math.log2(output_stride)))].shape.as_list(),
101+
)
89102

90103
@combinations.generate(
91104
combinations.combine(

0 commit comments

Comments
 (0)