Ejemplo n.º 1
0
    def test_container_get_commands_empty(self):

        reg = Registry()
        reg.register(FakeApp2())

        commands = reg.get_commands()
        self.assertFalse(len(commands) > 0)
Ejemplo n.º 2
0
    def test_container_get_commands(self):

        reg = Registry()
        reg.register(FakeApp1())
        reg.register(FakeApp2())

        commands = reg.get_commands()
        self.assertTrue(len(commands) > 0)
Ejemplo n.º 3
0
    def test_build_registry(self):

        reg = Registry()
        reg.register(FakeApp1())
        reg.register(FakeApp2())
        reg.register(FakeApp4())

        # check if list of apps is not empty list
        self.assertIsNot(reg.get_apps(), [])
        self.assertEqual(3, len(reg.get_apps()))
        self.assertEqual(3, len(reg.get_routes()))
Ejemplo n.º 4
0
    def test_container_error(self):

        # test if application not implement container abstract class
        with self.assertRaises(ContainerError) as container_error:
            reg = Registry()
            reg.register(FakeApp3())

        exception = container_error.exception
        self.assertEqual('FakeApp3', exception.app_name)
        self.assertEqual(
            'ContainerError: Cannot use FakeApp3 as container application',
            exception.message)
 def setUp(self):
     self._subscriber_registry = Registry()
     self._commandProcessor = CommandProcessor(
         registry=self._subscriber_registry)
Ejemplo n.º 6
0
import torch
import torch.nn as nn

from core.registry import Registry
from core.trainer import _initialize_weights
from .ml_heads import build_ml_head
from .layers import LocalBlock

MODEL_REGISTRY = Registry("MODEL_TYPE")
MODEL_REGISTRY.__doc__ = """
Registry for Mammo models.
"""

BACKBONE_REGISTRY = Registry("BACKBONE_TYPE")
BACKBONE_REGISTRY.__doc__ = """
Registry for Mammo cls backbone.
"""


def build_model(cfg):
    """Build the whole model architecture
    """
    model_name = cfg.MODEL.NAME
    model = MODEL_REGISTRY.get(model_name)(cfg)
    return model


@MODEL_REGISTRY.register()
class ResNet_v0(nn.Module):
    """Original ResNet
    """
Ejemplo n.º 7
0
import math
import torch
import torch.nn as nn
import torch.nn.functional as F

from core.registry import Registry

ML_HEAD_REGISTRY = Registry("ML_HEAD")
ML_HEAD_REGISTRY.__doc__ = """
Registry for metric learning heads.
"""


def build_ml_head(cfg, in_channels):
    head_name = cfg.MODEL.ML_HEAD.NAME
    out_channels = cfg.MODEL.NUM_CLASSES
    s = cfg.MODEL.ML_HEAD.SCALER
    m = cfg.MODEL.ML_HEAD.MARGIN
    num_centers = cfg.MODEL.ML_HEAD.NUM_CENTERS
    head = ML_HEAD_REGISTRY.get(head_name)(in_channels, out_channels, s, m,
                                           num_centers)
    return head


@ML_HEAD_REGISTRY.register()
class ArcFace(nn.Module):
    """
    This module implements ArcFace.
    """
    def __init__(self, in_channels, out_channels, s=32., m=0.5, num_centers=1):
        super(ArcFace, self).__init__()
Ejemplo n.º 8
0
from core.buffer import Buffer
from core.test_buffer import TestBuffer
from core.registry import Registry

########## App setup ##########
app = Application()
r = app.router

########## Instantiate globals ##########
env_type = os.environ.get('ENV_TYPE')
if env_type == "production":
    buffer = Buffer()
else:
    buffer = TestBuffer()

registry = Registry(buffer=buffer)

########## Error handling ##########


def get_required_param(json, param):
    if json is None:
        logger.info("Request is not a valid json")
        raise InvalidUsage("Request is not a valid json")
    value = json.get(param, None)
    if (value is None) or (value == '') or (value == []):
        logger.info("A required request parameter '{}' had value {}".format(
            param, value))
        raise InvalidUsage(
            "A required request parameter '{}' was not provided".format(param))
    return value
Ejemplo n.º 9
0
    def __init__(
        self,
        random_seed: Optional[int] = None,
        force_cache_refresh: bool = False,
        nomorphi: bool = False,
        planner: str = "full",
    ) -> None:
        """
        :param random_seed: seed for random number generation, for repeatability
        :param force_cache_refresh:
        :param nomorphi: don't load Omorphi for morphological generation. This removes the dependency on Omorphi,
            so allows easier setup, but means that no morphological inflection will be performed on the output,
            which is generally a very bad thing for the full pipeline
        """

        # New registry and result importer
        self.registry = Registry()

        # DataSets
        DATA_ROOT = Path(__file__).parent.absolute() / ".." / "data"

        self.datasets = [
            "cphi",
            "health_cost",
            "health_funding",
        ]
        for dataset in self.datasets:
            cache_path: Path = (DATA_ROOT / "{}.cache".format(dataset)).absolute()
            if not cache_path.exists():
                raise IOError("No cached dataset found at {}. Datasets must be generated before startup.")
            self.registry.register("{}-data".format(dataset), DataFrameStore(str(cache_path)))

        # Resources
        self.resources = [
            CPHIEnglishResource(),
            CPHIFinnishResource(),
            CPHICroatianResource(),
            CPHIRussianResource(),
            CPHIEstonianResource(),
            CPHISlovenianResource(),
            ENVEnglishResource(),
            ENVFinnishResource(),
            HealthCostEnglishResource(),
            HealthCostFinnishResource(),
            HealthFundingEnglishResource(),
            HealthFundingFinnishResource(),
        ]

        # Templates
        self.registry.register("templates", self._load_templates())

        # Slot Realizers:
        realizers: List[SlotRealizerComponent] = []
        for resource in self.resources:
            for realizer in resource.slot_realizer_components():
                realizers.append(realizer(self.registry))
        self.registry.register("slot-realizers", realizers)

        # Language metadata
        self.registry.register("conjunctions", CONJUNCTIONS)
        self.registry.register("errors", ERRORS)

        # PRNG seed
        self._set_seed(seed_val=random_seed)

        def _get_components(headline=False, planner="full"):
            # Put together the list of components
            # This varies depending on whether it's for headlines and which language we are doing stuff in
            yield EUMessageGenerator(expand=True)
            yield EUImportanceSelector()
            if planner == "random":
                yield EURandomHeadlineDocumentPlanner() if headline else EURandomBodyDocumentPlanner()
            elif planner == "score":
                yield EUScoreHeadlineDocumentPlanner() if headline else EUScoreBodyDocumentPlanner()
            elif planner == "earlystop":
                yield EUEarlyStopHeadlineDocumentPlanner() if headline else EUEarlyStopBodyDocumentPlanner()
            elif planner == "topicsim":
                yield EUTopicSimHeadlineDocumentPlanner() if headline else EUTopicSimBodyDocumentPlanner()
            elif planner == "contextsim":
                yield EUContextSimHeadlineDocumentPlanner() if headline else EUContextSimBodyDocumentPlanner()
            elif planner == "neuralsim":
                if headline:
                    yield EUHeadlineDocumentPlanner()
                else:
                    yield TemplateAttacher()
                    yield EUNeuralSimBodyDocumentPlanner()
                    yield EmbeddingRemover()

            elif planner == "full":
                yield EUHeadlineDocumentPlanner() if headline else EUBodyDocumentPlanner()
            else:
                raise ValueError("INCORRECT PLANNER SETTING")
            yield TemplateSelector()
            yield Aggregator()
            yield SlotRealizer()
            yield LanguageSplitComponent(
                {
                    "en": EnglishEUDateRealizer(),
                    "fi": FinnishEUDateRealizer(),
                    "hr": CroatianEUDateRealizer(),
                    "de": GermanEUDateRealizer(),
                    "ru": RussianEUDateRealizer(),
                    "ee": EstonianEUDateRealizer(),
                    "sl": SlovenianEUDateRealizer(),
                }
            )
            yield EUEntityNameResolver()
            yield EUNumberRealizer()
            yield MorphologicalRealizer(
                {
                    "en": EnglishUralicNLPMorphologicalRealizer(),
                    "fi": FinnishUralicNLPMorphologicalRealizer(),
                    "hr": CroatianSimpleMorphologicalRealizer(),
                    "ru": RussianMorphologicalRealizer(),
                    "ee": EstonianUralicNLPMorphologicalRealizer(),
                    "sl": SlovenianSimpleMorphologicalRealizer(),
                }
            )
            yield HeadlineHTMLSurfaceRealizer() if headline else BodyHTMLSurfaceRealizer()

        log.info("Configuring Body NLG Pipeline (planner = {})".format(planner))
        self.body_pipeline = NLGPipeline(self.registry, *_get_components(planner=planner))
        self.headline_pipeline = NLGPipeline(self.registry, *_get_components(headline=True, planner=planner))
Ejemplo n.º 10
0
from apps.hello.routes import app as HelloApp
from apps.ping.routes import app as PingApp
from apps.mongo.routes import app as MongoApp
from core.registry import Registry
from core.exceptions.application import ContainerError

try:
    """
    You should register all of your apps here.
    """
    apps = Registry()
    apps.register(HelloApp)
    apps.register(PingApp)
    apps.register(MongoApp)

except ContainerError, e:
    """
    I cannot use logging here.  If i use default logging here,
    it will reset all tornado's logging configurations, so i just
    use simple print statement.
    """
    print e.message
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-

from core.registry import Registry

# classic models used as backbones
BACKBONES = Registry('backbones')

# modules used for extracting features
FEATURE_EXTRACTORS = Registry('feature_extractors')

LOSSES = Registry('losses')

# whole models used as detectors
DETECTORS = Registry('detectors')

# bbox coder(transform bbox format)
BBOX_CODERS = Registry('bbox_coder')

# similarity_calc
SIMILARITY_CALCS = Registry('similarity_calcs')

# matcher
MATCHERS = Registry('matchers')

# anchor_generators
ANCHOR_GENERATORS = Registry('anchor_generators')

# dataset and dataloaders
DATASETS = Registry('datasets')
DATALOADERS = Registry('dataloaders')
Ejemplo n.º 12
0
from core.registry import Registry
from models.tf_keras_model import TFKerasModel
from models.tf_v1_model import TFV1Model

model_registry = Registry('Model')

from models.q_model import *
from models.ac_model import *
from models.q_model_keras import *
from models.ac_model_keras import *
from models.custom_model import *