@@ -138,17 +138,19 @@ class DefaultBoxGenerator(nn.Module):
138
138
Args:
139
139
aspect_ratios (List[List[int]]): A list with all the aspect ratios used in each feature map.
140
140
min_ratio (float): The minimum scale :math:`\t ext{s}_{\t ext{min}}` of the default boxes used in the estimation
141
- of the scales of each feature map.
141
+ of the scales of each feature map. It is used only if the ``scales`` parameter is not provided.
142
142
max_ratio (float): The maximum scale :math:`\t ext{s}_{\t ext{max}}` of the default boxes used in the estimation
143
- of the scales of each feature map.
143
+ of the scales of each feature map. It is used only if the ``scales`` parameter is not provided.
144
+ scales (List[float]], optional): The scales of the default boxes. If not provided it will be estimated using
145
+ the ``min_ratio`` and ``max_ratio`` parameters.
144
146
steps (List[int]], optional): It's a hyper-parameter that affects the tiling of defalt boxes. If not provided
145
147
it will be estimated from the data.
146
148
clip (bool): Whether the standardized values of default boxes should be clipped between 0 and 1. The clipping
147
149
is applied while the boxes are encoded in format ``(cx, cy, w, h)``.
148
150
"""
149
151
150
152
def __init__ (self , aspect_ratios : List [List [int ]], min_ratio : float = 0.15 , max_ratio : float = 0.9 ,
151
- steps : Optional [List [int ]] = None , clip : bool = True ):
153
+ scales : Optional [ List [ float ]] = None , steps : Optional [List [int ]] = None , clip : bool = True ):
152
154
super ().__init__ ()
153
155
if steps is not None :
154
156
assert len (aspect_ratios ) == len (steps )
@@ -158,15 +160,12 @@ def __init__(self, aspect_ratios: List[List[int]], min_ratio: float = 0.15, max_
158
160
num_outputs = len (aspect_ratios )
159
161
160
162
# Estimation of default boxes scales
161
- # Inspired from https://github.com/weiliu89/caffe/blob/ssd/examples/ssd/ssd_pascal.py#L311-L317
162
- min_centile = int (100 * min_ratio )
163
- max_centile = int (100 * max_ratio )
164
- conv4_centile = min_centile // 2 # assume half of min_ratio as in paper
165
- step = (max_centile - min_centile ) // (num_outputs - 2 )
166
- centiles = [conv4_centile , min_centile ]
167
- for c in range (min_centile , max_centile + 1 , step ):
168
- centiles .append (c + step )
169
- self .scales = [c / 100 for c in centiles ]
163
+ if scales is None :
164
+ range_ratio = max_ratio - min_ratio
165
+ self .scales = [min_ratio + range_ratio * k / (num_outputs - 1.0 ) for k in range (num_outputs )]
166
+ self .scales .append (1.0 )
167
+ else :
168
+ self .scales = scales
170
169
171
170
self ._wh_pairs = []
172
171
for k in range (num_outputs ):
0 commit comments