当前位置: 首页>>代码示例>>Python>>正文


Python base_model.BaseModel方法代码示例

本文整理汇总了Python中models.base_model.BaseModel方法的典型用法代码示例。如果您正苦于以下问题:Python base_model.BaseModel方法的具体用法?Python base_model.BaseModel怎么用?Python base_model.BaseModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.base_model的用法示例。


在下文中一共展示了base_model.BaseModel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_model_using_name

# 需要导入模块: from models import base_model [as 别名]
# 或者: from models.base_model import BaseModel [as 别名]
def find_model_using_name(model_name):
    # Given the option --model [modelname],
    # the file "models/modelname_model.py"
    # will be imported.
    model_filename = "models." + model_name + "_model"
    modellib = importlib.import_module(model_filename)

    # In the file, the class called ModelNameModel() will
    # be instantiated. It has to be a subclass of BaseModel,
    # and it is case-insensitive.
    model = None
    target_model_name = model_name.replace('_', '') + 'model'
    for name, cls in modellib.__dict__.items():
        if name.lower() == target_model_name.lower() \
           and issubclass(cls, BaseModel):
            model = cls

    if model is None:
        print("In %s.py, there should be a subclass of BaseModel with class name that matches %s in lowercase." % (model_filename, target_model_name))
        exit(0)

    return model 
开发者ID:Lotayou,项目名称:densebody_pytorch,代码行数:24,代码来源:__init__.py

示例2: create_model

# 需要导入模块: from models import base_model [as 别名]
# 或者: from models.base_model import BaseModel [as 别名]
def create_model(opt):
    model_filename = "models." + opt.model_name + '_model'
    modellib = importlib.import_module(model_filename)
    model = None
    target_model_name = opt.model_name.replace('_', '') + 'model'
    for name, cls in modellib.__dict__.items():
        if name.lower() == target_model_name.lower() \
           and issubclass(cls, BaseModel):
            model = cls
    if model is None:
        raise NotImplementedError("In %s.py, there should be a subclass of BaseModel with class name that matches %s in lowercase." % (model_filename, target_model_name))
    return model(opt) 
开发者ID:Xiaoming-Yu,项目名称:DMIT,代码行数:14,代码来源:__init__.py

示例3: eval

# 需要导入模块: from models import base_model [as 别名]
# 或者: from models.base_model import BaseModel [as 别名]
def eval(self, net=None, logger=None):
        """Make specific models eval mode during test time"""
        # if issubclass(net, nn.Module) or issubclass(net, BaseModel):
        if net == None:
            for net in self.nets:
                net.eval()
            for net in self.nets_DP:
                net.eval()
            if logger!=None:    
                logger.info("Successfully set the model eval mode") 
        else:
            net.eval()
            if logger!=None:    
                logger("Successfully set {} eval mode".format(net.__class__.__name__))
        return 
开发者ID:RogerZhangzz,项目名称:CAG_UDA,代码行数:17,代码来源:adaptation_model.py

示例4: set_requires_grad

# 需要导入模块: from models import base_model [as 别名]
# 或者: from models.base_model import BaseModel [as 别名]
def set_requires_grad(self, logger, net, requires_grad = False):
        """Set requires_grad=Fasle for all the networks to avoid unnecessary computations
        Parameters:
            net (BaseModel)       -- the network which will be operated on
            requires_grad (bool)  -- whether the networks require gradients or not
        """
        # if issubclass(net, nn.Module) or issubclass(net, BaseModel):
        for parameter in net.parameters():
            parameter.requires_grad = requires_grad
        # print("Successfully set {} requires_grad with {}".format(net.__class__.__name__, requires_grad))
        # return 
开发者ID:RogerZhangzz,项目名称:CAG_UDA,代码行数:13,代码来源:adaptation_model.py


注:本文中的models.base_model.BaseModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。