Esempio n. 1
0
def import_collable_lazy(collableString):
    """
    This method is aimed to import a collable method or attribute
    within a module that needs to be lazy imported
    @ In, moduleString, str, the collable to point (e.g. numpy.arange, numpy.ndarray, etc.)
    @ Out, callable, Object_Pointer, the collable (lazy)
  """
    return lazy_import.lazy_callable(collableString.strip())
Esempio n. 2
0
import logging
import typing

import numpy as np
from lazy_import import lazy_callable
from scipy import optimize

from smac.configspace import ConfigurationSpace
from smac.epm.base_gp import BaseModel
from smac.utils.constants import VERY_SMALL_NUMBER

logger = logging.getLogger(__name__)
Kernel = lazy_callable('skopt.learning.gaussian_process.kernels.Kernel')
GaussianProcessRegressor = lazy_callable(
    'skopt.learning.gaussian_process.GaussianProcessRegressor')


class GaussianProcess(BaseModel):
    """
    Gaussian process model.

    The GP hyperparameterŝ are obtained by optimizing the marginal log likelihood.

    This code is based on the implementation of RoBO:

    Klein, A. and Falkner, S. and Mansur, N. and Hutter, F.
    RoBO: A Flexible and Robust Bayesian Optimization Framework in Python
    In: NIPS 2017 Bayesian Optimization Workshop

    Parameters
    ----------
from .dataset import BaseDataset, Literal, Iterable
import lazy_import
import os
h5py = lazy_import.lazy_module("h5py")
groupby = lazy_import.lazy_callable("itertools.groupby")
ZipFile = lazy_import.lazy_callable("zipfile.ZipFile")
re = lazy_import.lazy_module("re")


class NYUDataset(BaseDataset):
    ID: Literal['NYU']
    zip_file_loc: str
    gt_file_loc: str

    @property
    def scenes(self) -> Iterable:
        """
        Loads the various scenes in the NYU dataset
        :return: None
        """
        zip_f = ZipFile(self.zip_file_loc)
        scene_frames = {
            k: self.synchronise_frames(frames)
            for k, frames in self.split_namelist_into_scenes(
                zip_f.namelist()).items()
        }

        with h5py.File(self.gt_file_loc, 'r') as f:
            depth_frame_names = [
                f[frame][()].tobytes().decode('utf16')
                for frame in f.get('rawDepthFilenames')[0]
import os

from lazy_import import lazy_module, lazy_callable
import numpy as np
from importlib import reload

from nachbarstrom.commons.image_provider import ImageProvider
from nachbarstrom.commons.world import Location, Roof, RoofType, RoofOrientation
from nachbarstrom.inference.file_updater import FileUpdater
from . import RoofProvider

# Keras with Tensorflow backend takes a long time to load, so we use a
# lighter model for development and load Keras lazily.
backend = lazy_module("keras.backend")
load_model = lazy_callable("keras.models.load_model")

ROOF_TYPE_MODEL = "roof_type_model.h5"
ROOF_ORIENTATION_MODEL = "roof_orientation_model.h5"
ROOF_AREA_MODEL = "roof_area_model.h5"
MODELS_FOLDER = "model"


class TensorFlowRoofProvider(RoofProvider):

    _IMAGE_SIZE = (299, 299)
    _MODEL_NAMES = [ROOF_AREA_MODEL, ROOF_ORIENTATION_MODEL, ROOF_TYPE_MODEL]

    def __init__(self, model_updater: FileUpdater,
                 image_provider: ImageProvider) -> None:
        self._set_tensorflow_backend()
        self._image_provider = image_provider