本文整理匯總了Python中chainer.optimizers.AdaGrad方法的典型用法代碼示例。如果您正苦於以下問題:Python optimizers.AdaGrad方法的具體用法?Python optimizers.AdaGrad怎麽用?Python optimizers.AdaGrad使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chainer.optimizers
的用法示例。
在下文中一共展示了optimizers.AdaGrad方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_optimizer
# 需要導入模塊: from chainer import optimizers [as 別名]
# 或者: from chainer.optimizers import AdaGrad [as 別名]
def get_optimizer(opt, lr=None, adam_alpha=None, adam_beta1=None,
adam_beta2=None, adam_eps=None, weight_decay=None):
if opt == 'MomentumSGD':
optimizer = optimizers.MomentumSGD(lr=lr, momentum=0.9)
elif opt == 'Adam':
optimizer = optimizers.Adam(
alpha=adam_alpha, beta1=adam_beta1,
beta2=adam_beta2, eps=adam_eps)
elif opt == 'AdaGrad':
optimizer = optimizers.AdaGrad(lr=lr)
elif opt == 'RMSprop':
optimizer = optimizers.RMSprop(lr=lr)
else:
raise Exception('No optimizer is selected')
# The first model as the master model
if opt == 'MomentumSGD':
optimizer.decay = weight_decay
return optimizer
示例2: get_model_optimizer
# 需要導入模塊: from chainer import optimizers [as 別名]
# 或者: from chainer.optimizers import AdaGrad [as 別名]
def get_model_optimizer(args):
model = get_model(args)
if 'opt' in args:
# prepare optimizer
if args.opt == 'MomentumSGD':
optimizer = optimizers.MomentumSGD(lr=args.lr, momentum=0.9)
elif args.opt == 'Adam':
optimizer = optimizers.Adam(alpha=args.alpha)
elif args.opt == 'AdaGrad':
optimizer = optimizers.AdaGrad(lr=args.lr)
else:
raise Exception('No optimizer is selected')
optimizer.setup(model)
if args.opt == 'MomentumSGD':
optimizer.add_hook(
chainer.optimizer.WeightDecay(args.weight_decay))
if args.resume_opt is not None:
serializers.load_hdf5(args.resume_opt, optimizer)
args.epoch_offset = int(
re.search('epoch-([0-9]+)', args.resume_opt).groups()[0])
return model, optimizer
else:
print('No optimizer generated.')
return model
示例3: create
# 需要導入模塊: from chainer import optimizers [as 別名]
# 或者: from chainer.optimizers import AdaGrad [as 別名]
def create(self):
return optimizers.AdaGrad(0.1)
示例4: get_optimizer
# 需要導入模塊: from chainer import optimizers [as 別名]
# 或者: from chainer.optimizers import AdaGrad [as 別名]
def get_optimizer(model, opt, lr, adam_alpha=None, adam_beta1=None,
adam_beta2=None, adam_eps=None, weight_decay=None,
resume_opt=None):
if opt == 'MomentumSGD':
optimizer = optimizers.MomentumSGD(lr=lr, momentum=0.9)
elif opt == 'Adam':
optimizer = optimizers.Adam(
alpha=adam_alpha, beta1=adam_beta1,
beta2=adam_beta2, eps=adam_eps)
elif opt == 'AdaGrad':
optimizer = optimizers.AdaGrad(lr=lr)
elif opt == 'RMSprop':
optimizer = optimizers.RMSprop(lr=lr)
else:
raise Exception('No optimizer is selected')
# The first model as the master model
optimizer.setup(model)
if opt == 'MomentumSGD':
optimizer.add_hook(
chainer.optimizer.WeightDecay(weight_decay))
if resume_opt is not None:
serializers.load_npz(resume_opt, optimizer)
return optimizer
示例5: create_args
# 需要導入模塊: from chainer import optimizers [as 別名]
# 或者: from chainer.optimizers import AdaGrad [as 別名]
def create_args():
parser = argparse.ArgumentParser()
# Training settings
parser.add_argument('--model', type=str,
default='models/MnihCNN_multi.py')
parser.add_argument('--gpu', type=int, default=0)
parser.add_argument('--epoch', type=int, default=400)
parser.add_argument('--batchsize', type=int, default=128)
parser.add_argument('--dataset_size', type=float, default=1.0)
parser.add_argument('--aug_threads', type=int, default=8)
parser.add_argument('--snapshot', type=int, default=10)
parser.add_argument('--resume_model', type=str, default=None)
parser.add_argument('--resume_opt', type=str, default=None)
parser.add_argument('--epoch_offset', type=int, default=0)
# Dataset paths
parser.add_argument('--train_ortho_db', type=str,
default='data/mass_merged/lmdb/train_sat')
parser.add_argument('--train_label_db', type=str,
default='data/mass_merged/lmdb/train_map')
parser.add_argument('--valid_ortho_db', type=str,
default='data/mass_merged/lmdb/valid_sat')
parser.add_argument('--valid_label_db', type=str,
default='data/mass_merged/lmdb/valid_map')
# Dataset info
parser.add_argument('--ortho_original_side', type=int, default=92)
parser.add_argument('--label_original_side', type=int, default=24)
parser.add_argument('--ortho_side', type=int, default=64)
parser.add_argument('--label_side', type=int, default=16)
# Options for data augmentation
parser.add_argument('--fliplr', type=int, default=1)
parser.add_argument('--rotate', type=int, default=1)
parser.add_argument('--angle', type=int, default=90)
parser.add_argument('--norm', type=int, default=1)
parser.add_argument('--crop', type=int, default=1)
# Optimization settings
parser.add_argument('--opt', type=str, default='MomentumSGD',
choices=['MomentumSGD', 'Adam', 'AdaGrad'])
parser.add_argument('--weight_decay', type=float, default=0.0005)
parser.add_argument('--alpha', type=float, default=0.001)
parser.add_argument('--lr', type=float, default=0.0005)
parser.add_argument('--lr_decay_freq', type=int, default=100)
parser.add_argument('--lr_decay_ratio', type=float, default=0.1)
parser.add_argument('--seed', type=int, default=1701)
args = parser.parse_args()
return args