本文整理汇总了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
示例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)
示例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
示例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