You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

make_divisible.py 1.3 kB

2 years ago
12345678910111213141516171819202122232425262728
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. def make_divisible(value, divisor, min_value=None, min_ratio=0.9):
  3. """Make divisible function.
  4. This function rounds the channel number to the nearest value that can be
  5. divisible by the divisor. It is taken from the original tf repo. It ensures
  6. that all layers have a channel number that is divisible by divisor. It can
  7. be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py # noqa
  8. Args:
  9. value (int): The original channel number.
  10. divisor (int): The divisor to fully divide the channel number.
  11. min_value (int): The minimum value of the output channel.
  12. Default: None, means that the minimum value equal to the divisor.
  13. min_ratio (float): The minimum ratio of the rounded channel number to
  14. the original channel number. Default: 0.9.
  15. Returns:
  16. int: The modified output channel number.
  17. """
  18. if min_value is None:
  19. min_value = divisor
  20. new_value = max(min_value, int(value + divisor / 2) // divisor * divisor)
  21. # Make sure that round down does not go down by more than (1-min_ratio).
  22. if new_value < min_ratio * value:
  23. new_value += divisor
  24. return new_value

No Description

Contributors (1)