anchor_generator
AnchorGenerator
Bases: object
Standard anchor generator for 2D anchor-based detectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strides |
list[int]
|
Strides of anchors in multiple feture levels. |
required |
ratios |
list[float]
|
The list of ratios between the height and width of anchors in a single level. |
required |
scales |
list[int] | None
|
Anchor scales for anchors in a single level.
It cannot be set at the same time if |
None
|
base_sizes |
list[int] | None
|
The basic sizes of anchors in multiple levels. If None is given, strides will be used as base_sizes. |
None
|
scale_major |
bool
|
Whether to multiply scales first when generating base anchors. If true, the anchors in the same row will have the same scales. By default it is True in V2.0 |
True
|
octave_base_scale |
int
|
The base scale of octave. |
None
|
scales_per_octave |
int
|
Number of scales for each octave.
|
None
|
centers |
list[tuple[float, float]] | None
|
The centers of the anchor relative to the feature grid center in multiple feature levels. By default it is set to be None and not used. If a list of tuple of float is given, they will be used to shift the centers of anchors. |
None
|
center_offset |
float
|
The offset of center in propotion to anchors' width and height. By default it is 0 in V2.0. |
0.0
|
Examples:
>>> from mmdet.core import AnchorGenerator
>>> self = AnchorGenerator([16], [1.], [1.], [9])
>>> all_anchors = self.grid_anchors([(2, 2)], device='cpu')
>>> print(all_anchors)
[tensor([[-4.5000, -4.5000, 4.5000, 4.5000],
[11.5000, -4.5000, 20.5000, 4.5000],
[-4.5000, 11.5000, 4.5000, 20.5000],
[11.5000, 11.5000, 20.5000, 20.5000]])]
>>> self = AnchorGenerator([16, 32], [1.], [1.], [9, 18])
>>> all_anchors = self.grid_anchors([(2, 2), (1, 1)], device='cpu')
>>> print(all_anchors)
[tensor([[-4.5000, -4.5000, 4.5000, 4.5000],
[11.5000, -4.5000, 20.5000, 4.5000],
[-4.5000, 11.5000, 4.5000, 20.5000],
[11.5000, 11.5000, 20.5000, 20.5000]]), tensor([[-9., -9., 9., 9.]])]
Source code in pyodi/core/anchor_generator.py
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
num_levels: int
property
Returns the number of levels.
Returns:
Type | Description |
---|---|
int
|
Number of levels. |
gen_base_anchors()
Computes the anchors.
Returns:
Type | Description |
---|---|
List[ndarray]
|
List of arrays with the anchors. |
Source code in pyodi/core/anchor_generator.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
gen_single_level_base_anchors(base_size, scales, ratios, center=None)
Computes the anchors of a single level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_size |
int
|
Basic size of the anchors in a single level. |
required |
scales |
ndarray
|
Anchor scales for anchors in a single level |
required |
ratios |
ndarray
|
Ratios between height and width of anchors in a single level. |
required |
center |
Optional[Tuple[float, float]]
|
Center of the anchor relative to the feature grid center in single level. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
Array with the anchors. |
Source code in pyodi/core/anchor_generator.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
grid_anchors(featmap_sizes)
Generate grid anchors in multiple feature levels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
featmap_sizes |
List[Tuple[int, int]]
|
List of feature map sizes in multiple feature levels. |
required |
Returns:
Type | Description |
---|---|
List[ndarray]
|
Anchors in multiple feature levels. The sizes of each tensor should be |
List[ndarray]
|
[N, 4], where N = width * height * num_base_anchors, width and height are |
List[ndarray]
|
the sizes of the corresponding feature level, num_base_anchors is the |
List[ndarray]
|
number of anchors for that level. |
Source code in pyodi/core/anchor_generator.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
single_level_grid_anchors(base_anchors, featmap_size, stride=16)
Generate grid anchors in a single feature level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_anchors |
ndarray
|
Anchors in a single level. |
required |
featmap_size |
Tuple[int, int]
|
Feature map size in a single level. |
required |
stride |
int
|
Number of stride. Defaults to 16. |
16
|
Returns:
Type | Description |
---|---|
ndarray
|
Grid of anchors in a single feature level. |
Source code in pyodi/core/anchor_generator.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
to_dict()
Transforms configuration into dictionary.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary with config. |
Source code in pyodi/core/anchor_generator.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
to_string()
Transforms configuration into string.
Returns:
Type | Description |
---|---|
str
|
String with config. |
Source code in pyodi/core/anchor_generator.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|