MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / random

Method random

models/utils.py:227–318  ·  view source on GitHub ↗

Create random AssignResult for tests or debugging. Args: num_preds: number of predicted boxes num_gts: number of true boxes p_ignore (float): probability of a predicted box assigned to an ignored truth p_assigned (float): proba

(cls, **kwargs)

Source from the content-addressed store, hash-verified

225
226 @classmethod
227 def random(cls, **kwargs):
228 """Create random AssignResult for tests or debugging.
229
230 Args:
231 num_preds: number of predicted boxes
232 num_gts: number of true boxes
233 p_ignore (float): probability of a predicted box assigned to an
234 ignored truth
235 p_assigned (float): probability of a predicted box not being
236 assigned
237 p_use_label (float | bool): with labels or not
238 rng (None | int | numpy.random.RandomState): seed or state
239
240 Returns:
241 :obj:`AssignResult`: Randomly generated assign results.
242
243 Example:
244 >>> from mmdet.core.bbox.assigners.assign_result import * # NOQA
245 >>> self = AssignResult.random()
246 >>> print(self.info)
247 """
248 from util.utils import ensure_rng
249 rng = ensure_rng(kwargs.get('rng', None))
250
251 num_gts = kwargs.get('num_gts', None)
252 num_preds = kwargs.get('num_preds', None)
253 p_ignore = kwargs.get('p_ignore', 0.3)
254 p_assigned = kwargs.get('p_assigned', 0.7)
255 p_use_label = kwargs.get('p_use_label', 0.5)
256 num_classes = kwargs.get('p_use_label', 3)
257
258 if num_gts is None:
259 num_gts = rng.randint(0, 8)
260 if num_preds is None:
261 num_preds = rng.randint(0, 16)
262
263 if num_gts == 0:
264 max_overlaps = torch.zeros(num_preds, dtype=torch.float32)
265 gt_inds = torch.zeros(num_preds, dtype=torch.int64)
266 if p_use_label is True or p_use_label < rng.rand():
267 labels = torch.zeros(num_preds, dtype=torch.int64)
268 else:
269 labels = None
270 else:
271 import numpy as np
272 # Create an overlap for each predicted box
273 max_overlaps = torch.from_numpy(rng.rand(num_preds))
274
275 # Construct gt_inds for each predicted box
276 is_assigned = torch.from_numpy(rng.rand(num_preds) < p_assigned)
277 # maximum number of assignments constraints
278 n_assigned = min(num_preds, min(num_gts, is_assigned.sum()))
279
280 assigned_idxs = np.where(is_assigned)[0]
281 rng.shuffle(assigned_idxs)
282 assigned_idxs = assigned_idxs[0:n_assigned]
283 assigned_idxs.sort()
284

Callers 5

forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
get_aug_configFunction · 0.45

Calls 2

ensure_rngFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected