Load or create a precise model

    Args:
        model_name: Name of model
        params: Parameters used to create the model

    Returns:
        model: Loaded Keras model
344833
def create_model(model_name: Optional[str], params: ModelParams) -> 'Sequential':
    
    if model_name and isfile(model_name):
        print('Loading from ' + model_name + '...')
        model = load_precise_model(model_name)
    else:
        from keras.layers.core import Dense
        from keras.layers.recurrent import GRU
        from keras.models import Sequential

        model = Sequential()
        model.add(GRU(
            params.recurrent_units, activation='linear',
            input_shape=(pr.n_features, pr.feature_size), dropout=params.dropout, name='net'
        ))
        model.add(Dense(1, activation='sigmoid'))

    load_keras()
    metrics = ['accuracy'] + params.extra_metrics * [false_pos, false_neg]
    set_loss_bias(params.loss_bias)
    for i in model.layers[:params.freeze_till]:
        i.trainable = False
    model.compile('rmsprop', weighted_log_loss, metrics=(not params.skip_acc) * metrics)
    return model
623927
def initialize_model(self, model):
        
        logging.info('Initializing fp32 clone weights')
        self.fp16_model = model
        self.fp16_model.zero_grad()
        self.fp32_params = [param.to(torch.float32).detach()
                            for param in model.parameters()]

        for param in self.fp32_params:
            param.requires_grad = True
1060278
def get_first_model_with_resource_name(cls, resource_name):
        

        models = cls.get_models_with_resource_name(resource_name)

        if len(models) > 0:
            return models[0]

        return None
173080
def use_model(self, model_name):
        
        # Check against exclude list.
        if self.exclude_models:
            for model_pattern in self.exclude_models:
                model_pattern = '^%s$' % model_pattern.replace('*', '.*')
                if re.search(model_pattern, model_name):
                    return False
        # Check against exclude list.
        elif self.include_models:
            for model_pattern in self.include_models:
                model_pattern = '^%s$' % model_pattern.replace('*', '.*')
                if re.search(model_pattern, model_name):
                    return True
        # Return `True` if `include_models` is falsey, otherwise return `False`.
        return not self.include_models
1067033
def init(req, model):  # pylint: disable=unused-argument
    

    params = {}

    for key, val in req.params.items():
        try:
            rtype, fields = _parse_param(key, val)
            params[rtype] = fields
        except TypeError:
            continue

    if params:
        _validate_req(req)
        for rtype, fields in params.items():
            _validate_param(rtype, fields)
    return params
387029
def get_model(app_label, model_name):
    
    try:
        return apps.get_model(app_label, model_name)
    except AppRegistryNotReady:
        if apps.apps_ready and not apps.models_ready:
            # If the models module of the considered app has not been loaded yet,
            # we try to import it manually in order to retrieve the model class.
            # This trick is usefull in order to get the model class during the
            # ``apps.populate()`` call and the execution of related methods of AppConfig
            # instances (eg. ``ready``).

            # Firts, the config of the consideration must be retrieved
            app_config = apps.get_app_config(app_label)
            # Then the models module is manually imported
            import_module('%s.%s' % (app_config.name, MODELS_MODULE_NAME))
            # Finally, tries to return the registered model class
            return apps.get_registered_model(app_label, model_name)
        else:
            raise
799405
def create(self, **kwargs):
        

        response = self.ghost.execute_post('%s/' % self._type_name, json={
            self._type_name: [
                kwargs
            ]
        })

        return self._model_type(response.get(self._type_name)[0])
704130
def build_model_input(cls, name='input'):
        
        return cls(name, PortDirection.INPUT, type=PortType.MODEL)
52785
def create_proxy_model(name, model_mixins, base_model, attrs=None, module=None):
    
    from django.apps import apps

    class Meta:
        proxy = True
        app_label = 'cmsplugin_cascade'

    name = str(name + 'Model')
    try:
        Model = apps.get_registered_model(Meta.app_label, name)
    except LookupError:
        bases = model_mixins + (base_model,)
        attrs = dict(attrs or {}, Meta=Meta, __module__=module)
        Model = type(name, bases, attrs)
        fake_proxy_models[name] = bases
    return Model
111031
def create_model(cls, name, field=None):
        
        if field:
            attrs = {'name': name, 'field': field}
        else:
            attrs = {'name': name, 'field': {'_id': ObjectId()}}

        return type(str(name), (cls, ), attrs)()
161028
def load_encoder(self, name:str, device:torch.device=None):
        ""
        encoder = get_model(self.model)[0]
        if device is None: device = self.data.device
        if hasattr(encoder, 'module'): encoder = encoder.module
        encoder.load_state_dict(torch.load(self.path/self.model_dir/f'{name}.pth'))
        encoder.load_state_dict(torch.load(self.path/self.model_dir/f'{name}.pth', map_location=device))
        self.freeze()
530617
def _load_source_model(self):
		

		# If source_model exists, return it
		if hasattr(self, "source_model"):
			return self.source_model

		# Getting the source model
		module = self.get_python_module()

		# Test if module has inside the model we are looking for
		if hasattr(module, self.model):
			# Setting of source model
			self.source_model = getattr(module, self.model)
			# Setting of verbose name and its plural for later use
			self.source_model.meta__verbose_name = self.source_model._meta.verbose_name
			self.source_model.meta__verbose_name_plural = self.source_model._meta.verbose_name_plural
			return self.source_model
		
		raise ValueError(u"Model {0} does not exist in module".format(self.model, self.module))
1085882
def find_model(sender, model_name):
    
    MC = get_mc()
    model = MC.get((MC.c.model_name==model_name) & (MC.c.uuid!=''))
    if model:
        model_inst = model.get_instance()
        orm.set_model(model_name, model_inst.table_name, appname=__name__, model_path='')
        return orm.__models__.get(model_name)
1264637
public function loadModel()
    {
        $modelClassName = $this->namespace . 'Models\Base';

        if (class_exists($modelClassName)) {
            models()->load($modelClassName, strtolower($this->type));
        }
    }
157908
def load(self, model):
        
        self.load_medium(model)
        self.load_essentiality(model)
        self.load_growth(model)
        # self.load_experiment(config.config.get("growth"), model)
        return self
544462
def model_get(method_name):
    

    def model_get(_value, context, **_params):
        method = getattr(context["model"], method_name)
        return _get(method, context["key"], (), {})

    return model_get
1357242
def get_models(args):
    
    if args:
        models = []
        for arg in args:
            match_found = False
            for model in registry.get_models():
                if model._meta.app_label == arg:
                    models.append(model)
                    match_found = True
                elif '%s.%s' % (model._meta.app_label, model._meta.model_name) == arg:
                    models.append(model)
                    match_found = True

            if not match_found:
                raise ValueError("No model or app named %s" % arg)
    else:
        models = registry.get_models()

    return set(models)