utils.py 1.2 KB
Newer Older
C
ceci3 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2019  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

C
ceci3 已提交
15 16
import math

C
update  
ceci3 已提交
17

C
ceci3 已提交
18 19 20 21 22 23 24
def compute_downsample_num(input_size, output_size):
    downsample_num = 0
    while input_size > output_size:
        input_size = math.ceil(float(input_size) / 2.0)
        downsample_num += 1

    if input_size != output_size:
C
update  
ceci3 已提交
25 26
        raise NotImplementedError(
            'output_size must can downsample by input_size!!!')
C
ceci3 已提交
27 28

    return downsample_num
C
update  
ceci3 已提交
29 30 31 32 33 34 35 36 37 38


def check_points(count, points):
    if points is None:
        return False
    else:
        if isinstance(points, list):
            return (True if count in points else False)
        else:
            return (True if count == points else False)