MCPcopy Create free account
hub / github.com/NVIDIA/DALI / make_batch_select_masks

Function make_batch_select_masks

dali/test/python/segmentation_test_utils.py:19–55  ·  view source on GitHub ↗
(
    batch_size,
    npolygons_range=(1, 10),
    nvertices_range=(3, 40),
    vertex_ndim=2,
    vertex_dtype=np.float32,
)

Source from the content-addressed store, hash-verified

17
18
19def make_batch_select_masks(
20 batch_size,
21 npolygons_range=(1, 10),
22 nvertices_range=(3, 40),
23 vertex_ndim=2,
24 vertex_dtype=np.float32,
25):
26 polygons = []
27 vertices = []
28 selected_masks = []
29 for _ in range(batch_size):
30 nmasks = random.randint(*npolygons_range)
31 available_masks = list(range(nmasks))
32 selected_masks.append(
33 np.array(random.sample(available_masks, random.randint(1, nmasks)), dtype=np.int32)
34 )
35 vertex_count = 0
36 mask_id = 0
37 curr_polygons = np.zeros([nmasks, 3], dtype=np.int32)
38 for m in range(nmasks):
39 nvertices = random.randint(*nvertices_range)
40 curr_polygons[m, :] = (mask_id, vertex_count, vertex_count + nvertices)
41 vertex_count = vertex_count + nvertices
42 mask_id = mask_id + 1
43 polygons.append(curr_polygons)
44 if np.issubdtype(vertex_dtype, np.integer):
45 vertices.append(
46 np.random.randint(
47 low=np.iinfo(vertex_dtype).min,
48 high=np.iinfo(vertex_dtype).max,
49 size=(vertex_count, vertex_ndim),
50 dtype=vertex_dtype,
51 )
52 )
53 else:
54 vertices.append(np.array(np.random.rand(vertex_count, vertex_ndim), dtype=vertex_dtype))
55 return polygons, vertices, selected_masks

Callers 4

get_data_sourceFunction · 0.90
get_data_sourceFunction · 0.90
get_data_sourceFunction · 0.90

Calls 2

sampleMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected