Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_custom_optim_range():
logger.debug('Start custom optimizer range')
opt = ag.optimizers.Adam(lr=ag.space.Log('lr', 10 ** -2, 10 ** -1),
wd=ag.space.Log('wd', 10 ** -6, 10 ** -2))
logger.debug(opt.hyper_params)
logger.debug('Finished.')
def test_log_space():
logger.debug('Start testing log space')
log_space = ag.space.Log('logspace', 10**-10, 10**-1)
print(log_space)
logger.debug('Finished.')
wd=ag.space.Categorical(1e-3, 1e-2))
def rl_train_fn(args, reporter):
for e in range(10):
dummy_accuracy = 1 - np.power(1.8, -np.random.uniform(e, 2*e))
reporter(epoch=e, accuracy=dummy_accuracy, lr=args.lr, wd=args.wd)
def test_custom_optim_range():
logger.debug('Start custom optimizer range')
opt = ag.optimizers.Adam(lr=ag.space.Log('lr', 10 ** -2, 10 ** -1),
wd=ag.space.Log('wd', 10 ** -6, 10 ** -2))
logger.debug(opt.hyper_params)
logger.debug('Finished.')
c=ag.space.Int(1, 10),
d=ag.space.Categorical('a', 'b', 'c', 'd'),
e=ag.space.Bool(),
f=ag.space.List(
ag.space.Int(1, 2),
ag.space.Categorical(4, 5),
),
g=ag.space.Dict(
a=ag.Real(0, 10),
obj=myobj(),
),
h=ag.space.Categorical('test', myobj()),
i = myfunc(),
)
def train_fn(args, reporter):
a, b, c, d, e, f, g, h, i = args.a, args.b, args.c, args.d, args.e, \
args.f, args.g, args.h, args.i
framework=ag.space.Categorical('mxnet', 'pytorch'),
)
def myfunc(framework):
return framework
def test_list_space():
logger.debug('Start testing list space')
list_space = ag.space.List('listspace', ['0',
'1',
'2'])
print(list_space)
logger.debug('Finished.')
import math
import autogluon as ag
from autogluon import ImageClassification as task
@ag.obj(
width_coefficient=ag.space.Categorical(1.1, 1.2),
depth_coefficient=ag.space.Categorical(1.1, 1.2),
)
class EfficientNetB1(ag.nas.EfficientNet):
def __init__(self, width_coefficient, depth_coefficient):
input_factor = math.sqrt(2.0 / (width_coefficient ** 2) / depth_coefficient)
input_size = math.ceil((224 * input_factor) / 32) * 32
super().__init__(width_coefficient=width_coefficient,
depth_coefficient=depth_coefficient,
input_size=input_size)
results = task.fit('imagenet', net=EfficientNetB1(), search_strategy='grid',
optimizer=ag.optimizer.SGD(learning_rate=1e-1,momentum=0.9,wd=1e-4),
batch_size=32)
print(results)
import math
import autogluon as ag
from autogluon import ImageClassification as task
@ag.obj(
width_coefficient=ag.space.Categorical(1.1, 1.2),
depth_coefficient=ag.space.Categorical(1.1, 1.2),
)
class EfficientNetB1(ag.nas.EfficientNet):
def __init__(self, width_coefficient, depth_coefficient):
input_factor = math.sqrt(2.0 / (width_coefficient ** 2) / depth_coefficient)
input_size = math.ceil((224 * input_factor) / 32) * 32
super().__init__(width_coefficient=width_coefficient,
depth_coefficient=depth_coefficient,
input_size=input_size)
results = task.fit('imagenet', net=EfficientNetB1(), search_strategy='grid',
optimizer=ag.optimizer.SGD(learning_rate=1e-1,momentum=0.9,wd=1e-4),
batch_size=32)
print(results)
lr=ag.space.Real(1e-2, 1e-1, log=True),
momentum=0.9,
wd=ag.space.Real(1e-5, 1e-3, log=True),
epochs=20,
)
def train_cifar(args, reporter):
print('args', args)
batch_size = args.batch_size
num_gpus = args.num_gpus
batch_size *= max(1, num_gpus)
context = [mx.gpu(i) for i in range(num_gpus)] if num_gpus > 0 else [mx.cpu()]
num_workers = args.num_workers
model_name = args.model
net = get_model(model_name, classes=10)