make_divisible.py 501 B

12345678910
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import math
  3. def make_divisible(x: float,
  4. widen_factor: float = 1.0,
  5. divisor: int = 8) -> int:
  6. """Make sure that x*widen_factor is divisible by divisor."""
  7. return math.ceil(x * widen_factor / divisor) * divisor
  8. def make_round(x: float, deepen_factor: float = 1.0) -> int:
  9. """Make sure that x*deepen_factor becomes an integer not less than 1."""
  10. return max(round(x * deepen_factor), 1) if x > 1 else x