Пример #1
0
def main(model, res=(512, ), pyramids=None, up_pyramid=False, max_depth=None):
    from hyperseg.utils.obj_factory import obj_factory
    from hyperseg.utils.utils import set_device
    from hyperseg.utils.img_utils import create_pyramid

    assert len(
        res
    ) <= 2, f'res must be either a single number or a pair of numbers: "{res}"'
    res = res * 2 if len(res) == 1 else res

    device, gpus = set_device()
    model = obj_factory(model).to(device)

    x = torch.rand(1, 3, *res).to(device)
    x = create_pyramid(x, pyramids) if pyramids is not None else x
    if up_pyramid:
        x.append(
            F.interpolate(x[0],
                          scale_factor=2,
                          mode='bilinear',
                          align_corners=False))  # Upsample x2

    # Run profile
    flops_summary, params_summary, meta_params_summary = profile(
        model, inputs=(x, ), max_depth=max_depth)
    print_summary(flops_summary, params_summary, meta_params_summary)
Пример #2
0
def main(model='hyperseg.models.hyperseg_v0_1.hyperseg_efficientnet',
         res=(512, ),
         pyramids=None,
         train=False):
    from hyperseg.utils.obj_factory import obj_factory
    from hyperseg.utils.utils import set_device
    from hyperseg.utils.img_utils import create_pyramid

    assert len(
        res
    ) <= 2, f'res must be either a single number or a pair of numbers: "{res}"'
    res = res * 2 if len(res) == 1 else res

    device, gpus = set_device()
    model = obj_factory(model).to(device).train(train)
    x = torch.rand(2, 3, *res).to(device)
    x = create_pyramid(x, pyramids) if pyramids is not None else x
    pred = model(x)
    print(pred.shape)
def main(model='hyperseg.models.hyperseg_v1_0.hypergen_efficientnet', res=(512,),
         pyramids=None,
         train=False):
    from hyperseg.utils.obj_factory import obj_factory
    from hyperseg.utils.utils import set_device
    from hyperseg.utils.img_utils import create_pyramid
    from tqdm import tqdm

    assert len(res) <= 2, f'res must be either a single number or a pair of numbers: "{res}"'
    res = res * 2 if len(res) == 1 else res

    torch.set_grad_enabled(False)
    torch.backends.cudnn.benchmark = True
    device, gpus = set_device()
    model = obj_factory(model).to(device).train(train)
    x = torch.rand(1, 3, *res).to(device)
    x = create_pyramid(x, pyramids) if pyramids is not None else x
    pred = model(x)
    print(pred.shape)
Пример #4
0
def main(model, res=(512, ), pyramids=None, max_depth=None):
    from hyperseg.utils.obj_factory import obj_factory
    from hyperseg.utils.utils import set_device
    from hyperseg.utils.img_utils import create_pyramid

    assert len(
        res
    ) <= 2, f'res must be either a single number or a pair of numbers: "{res}"'
    res = res * 2 if len(res) == 1 else res

    device, gpus = set_device()
    model = obj_factory(model).to(device)

    x = torch.rand(1, 3, *res).to(device)
    x = create_pyramid(x, pyramids) if pyramids is not None else x

    # Run profile
    flops_summary, params_summary = profile(model,
                                            inputs=(x, ),
                                            max_depth=max_depth)
    print_summary(flops_summary, params_summary)