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

Function update_map

dali/test/python/operator_2/test_remap.py:31–61  ·  view source on GitHub ↗

Code for map calculation. Based on https://github.com/opencv/opencv/blob/3.4/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py # noqa :param mode: One of: 'identity', 'xflip', 'yflip', 'xyflip', 'random' :param shape: HWC shape of a sample. :param nimages: Number of map

(mode, shape, nimages=1)

Source from the content-addressed store, hash-verified

29
30
31def update_map(mode, shape, nimages=1):
32 """
33 Code for map calculation.
34 Based on https://github.com/opencv/opencv/blob/3.4/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py # noqa
35 :param mode: One of: 'identity', 'xflip', 'yflip', 'xyflip', 'random'
36 :param shape: HWC shape of a sample.
37 :param nimages: Number of maps to be generated for every axis.
38 :return: tuple of 2 ndarrays (mapx: [nimages, H, W, C], mapy: [nimages, H, W, C])
39 """
40 mapsx = []
41 mapsy = []
42 for _ in range(nimages):
43 map_x = np.tile(np.arange(shape[1]), [shape[0], 1])
44 map_y = np.tile(np.arange(shape[0])[:, np.newaxis], [1, shape[1]])
45 if mode == "identity":
46 pass
47 elif mode == "xflip":
48 map_x = shape[1] - map_x
49 elif mode == "yflip":
50 map_y = shape[0] - map_y
51 elif mode == "xyflip":
52 map_x = shape[1] - map_x
53 map_y = shape[0] - map_y
54 elif mode == "random":
55 map_x = rng.uniform(low=0, high=map_x.shape[1] + 0, size=shape)
56 map_y = rng.uniform(low=0, high=map_y.shape[0] + 0, size=shape)
57 else:
58 raise ValueError("Unknown map mode.")
59 mapsx.append(map_x)
60 mapsy.append(map_y)
61 return np.array(mapsx, dtype=np.float32), np.array(mapsy, dtype=np.float32)
62
63
64def _cv_remap(img, mapx, mapy):

Callers 3

test_remapMethod · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected