本文整理匯總了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