def test_post_process_defaults_to_identity_function():
    model = init_model()
    wrapped_model = Wrapper(model)

    prediction = np.arange(64 * 64 * 1).reshape(1, 64, 64, 1)
    np.testing.assert_equal(
        wrapped_model.post_process(prediction),
        prediction
    )
def test_wrapper_resolve():
    model = init_model()
    wrapped_model = MyWrapper(model)

    assert Wrapper.resolve(wrapped_model.name) == MyWrapper

    class SubWrapper(MyWrapper):
        pass

    wrapped_model_b = SubWrapper(model)
    assert Wrapper.resolve(wrapped_model_b.name) == SubWrapper
예제 #3
0
def main():
    os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2'

    # SET MODEL
    u_net = UNet([32, 64, 128, 256, 512, 1024, 2048],
                 K,
                 None,
                 verbose=False,
                 useBN=True)
    if not os.path.exists(ROOT_DIR):
        raise Exception('Directory does not exist')

    state_dict = torch.load(TEST_UNET_WEIGHTS_PATH,
                            map_location=lambda storage, loc: storage)
    if 'checkpoint' in TEST_UNET_WEIGHTS_PATH:
        state_dict = state_dict['state_dict']
    new_state_dict = OrderedDict()

    for k, v in state_dict.items():
        name = k.replace('model.', '')
        new_state_dict[name] = v
    u_net.load_state_dict(new_state_dict, strict=True)
    model = Wrapper(u_net, main_device=MAIN_DEVICE)

    work = SpecChannelUnet(model,
                           ROOT_DIR,
                           PRETRAINED,
                           main_device=MAIN_DEVICE,
                           trackgrad=TRACKGRAD)
    work.model_version = 'UNIT_WEIGHTED_TESTING'
    work.train()
def test_wrapper_delegates_to_underlying_model():
    model = init_model()
    wrapped_model = Wrapper(model)

    assert wrapped_model.summary == wrapped_model.model.summary
    assert wrapped_model.fit     == wrapped_model.model.fit
    assert wrapped_model.predict == wrapped_model.model.predict
def test_resolve_uses_latest_wrapper():
    """
    This is mostly in place to support interactive use within Jupyter.
    We want to resolve the version of the wrapper that the user can
    actually _see_ - the latest version they wrote
    """
    global MyWrapper
    TestWrapperGlobal = MyWrapper

    class MyWrapper(Wrapper):
        pass

    model = models.Sequential([], name = 'model_name')
    wrapped_model = TestWrapperGlobal(model)

    assert Wrapper.resolve(wrapped_model.name) == MyWrapper
    assert Wrapper.resolve(wrapped_model.name) != TestWrapperGlobal
예제 #6
0
def main():
    os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2'

    # SET MODEL
    u_net = UNet([32, 64, 128, 256, 512, 1024, 2048], K, None, verbose=False, useBN=True, dropout=DROPOUT)
    model = Wrapper(u_net, main_device=MAIN_DEVICE)

    if not os.path.exists(ROOT_DIR):
        raise Exception('Directory does not exist')
    work = DWA(model, ROOT_DIR, PRETRAINED, main_device=MAIN_DEVICE, trackgrad=TRACKGRAD)
    work.model_version = 'DWA'
    work.train()
예제 #7
0
from xkcdpass import xkcd_password as xp
from pathlib import Path
from prettytable import PrettyTable
from collections import namedtuple

import warnings
import os
import sys
import click
import getopt

from datetime import date, datetime

from models.wrapper import Wrapper

w = Wrapper()


@click.group()
def cli():
    pass


@cli.command()
@click.argument('name', nargs=1, type=click.STRING)
@click.argument('email', nargs=1, type=click.STRING)
@click.option('--enabled/--disabled',
              default=True,
              help='Enables or disables an user account',
              is_flag=True)
@click.option('--expire',
def load(file_path):
    file_base_name = path.splitext(path.basename(file_path))[0]
    model = load_model(file_path)
    model.name = file_base_name.split('-')[-1]
    return Wrapper.resolve(file_base_name)(model)
def test_resize_defaults_to_throwing_not_implemented():
    wrapped_model = Wrapper(init_model())

    with pytest.raises(NotImplementedError):
        wrapped_model.resize((128, 128))
def test_wrapper_resolve_throws_if_model_is_untagged():
    model = init_model()

    with pytest.raises(Exception):
        Wrapper.resolve(model)
def test_compile_defaults_to_throwing_not_implemented():
    wrapped_model = Wrapper(init_model())

    with pytest.raises(NotImplementedError):
        wrapped_model.compile()