MCPcopy Create free account
hub / github.com/DragonisCV/RAM / get_soft_mask

Function get_soft_mask

scripts/analysis_utils.py:30–42  ·  view source on GitHub ↗

Generate a soft mask based on alpha value using sigmoid approximation.

(alpha, order_array, device, h, w, k=100)

Source from the content-addressed store, hash-verified

28 return mask
29
30def get_soft_mask(alpha, order_array, device, h, w, k=100):
31 """Generate a soft mask based on alpha value using sigmoid approximation."""
32 mask_count = int(np.ceil(len(order_array) * alpha))
33 mask_idx = order_array[:mask_count]
34 mask = np.zeros(len(order_array), dtype=float)
35
36 # Sigmoid approximation
37 for i, idx in enumerate(mask_idx):
38 mask[idx] = 1 / (1 + math.exp(-1 * k * (alpha - i / len(order_array))))
39
40 mask = mask.reshape(h, w)
41 mask = torch.FloatTensor(mask).to(device)
42 return mask
43
44def reduce_func(method):
45 """Return the corresponding reduction function."""

Calls

no outgoing calls

Tested by

no test coverage detected