Generate a soft mask based on alpha value using sigmoid approximation.
(alpha, order_array, device, h, w, k=100)
| 28 | return mask |
| 29 | |
| 30 | def 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 | |
| 44 | def reduce_func(method): |
| 45 | """Return the corresponding reduction function.""" |
no outgoing calls
no test coverage detected