forked from stone-ts15/tf_deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycommon.py
108 lines (93 loc) · 3.43 KB
/
mycommon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright 2018 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.
# ==============================================================================
"""Provides flags that are common to scripts.
Common flags from train/eval/vis/export_model.py are collected in this script.
"""
import collections
import copy
import tensorflow as tf
# {'semantic': 8} [1505, 2049] [6, 12, 18] 16 max True None True True None 4 True 1 xception_65 1.0
# Constants
A_merge_method = 'max'
A_add_image_level_feature = True
A_image_pooling_crop_size = None
A_aspp_with_batch_norm = True
A_aspp_with_separable_conv = True
A_multi_grid = None
A_decoder_output_stride = 4
A_decoder_use_separable_conv = True
A_logits_kernel_size = 1
A_model_variant = 'xception_65'
A_depth_multiplier = 1.0
# Perform semantic segmentation predictions.
OUTPUT_TYPE = 'semantic'
# Semantic segmentation item names.
LABELS_CLASS = 'labels_class'
IMAGE = 'image'
HEIGHT = 'height'
WIDTH = 'width'
IMAGE_NAME = 'image_name'
LABEL = 'label'
ORIGINAL_IMAGE = 'original_image'
# Test set name.
TEST_SET = 'test'
class ModelOptions(
collections.namedtuple('ModelOptions', [
'outputs_to_num_classes',
'crop_size',
'atrous_rates',
'output_stride',
'merge_method',
'add_image_level_feature',
'image_pooling_crop_size',
'aspp_with_batch_norm',
'aspp_with_separable_conv',
'multi_grid',
'decoder_output_stride',
'decoder_use_separable_conv',
'logits_kernel_size',
'model_variant',
'depth_multiplier',
])):
"""Immutable class to hold model options."""
__slots__ = ()
def __new__(cls,
outputs_to_num_classes,
crop_size=None,
atrous_rates=None,
output_stride=8):
"""Constructor to set default values.
Args:
outputs_to_num_classes: A dictionary from output type to the number of
classes. For example, for the task of semantic segmentation with 21
semantic classes, we would have outputs_to_num_classes['semantic'] = 21.
crop_size: A tuple [crop_height, crop_width].
atrous_rates: A list of atrous convolution rates for ASPP.
output_stride: The ratio of input to output spatial resolution.
Returns:
A new ModelOptions instance.
"""
return super(ModelOptions, cls).__new__(
cls, outputs_to_num_classes, crop_size, atrous_rates, output_stride,
A_merge_method, A_add_image_level_feature,
A_image_pooling_crop_size, A_aspp_with_batch_norm,
A_aspp_with_separable_conv, A_multi_grid,
A_decoder_output_stride, A_decoder_use_separable_conv,
A_logits_kernel_size, A_model_variant, A_depth_multiplier)
def __deepcopy__(self, memo):
return ModelOptions(copy.deepcopy(self.outputs_to_num_classes),
self.crop_size,
self.atrous_rates,
self.output_stride)