-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf57a1
commit 953dfb7
Showing
4 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from .make_divisible import make_divisible | ||
from .misc import add_prefix | ||
from .optim_wrapper import reinitialize_optim_wrapper_count_status | ||
|
||
__all__ = ['add_prefix', 'reinitialize_optim_wrapper_count_status'] | ||
__all__ = [ | ||
'add_prefix', 'reinitialize_optim_wrapper_count_status', 'make_divisible' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from typing import Optional | ||
|
||
|
||
def make_divisible(value: int, | ||
divisor: int, | ||
min_value: Optional[int] = None, | ||
min_ratio: float = 0.9) -> int: | ||
"""Make divisible function. | ||
This function rounds the channel number down to the nearest value that can | ||
be divisible by the divisor. | ||
Args: | ||
value (int): The original channel number. | ||
divisor (int): The divisor to fully divide the channel number. | ||
min_value (int, optional): The minimum value of the output channel. | ||
Default: None, means that the minimum value equal to the divisor. | ||
min_ratio (float): The minimum ratio of the rounded channel | ||
number to the original channel number. Default: 0.9. | ||
Returns: | ||
int: The modified output channel number | ||
""" | ||
|
||
if min_value is None: | ||
min_value = divisor | ||
new_value = max(min_value, int(value + divisor / 2) // divisor * divisor) | ||
# Make sure that round down does not go down by more than (1-min_ratio). | ||
if new_value < min_ratio * value: | ||
new_value += divisor | ||
return new_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters