Skip to content

Commit

Permalink
Demo (open-mmlab#20)
Browse files Browse the repository at this point in the history
* fix

* fix 1

* add notebook
  • Loading branch information
cgraywang authored May 22, 2019
1 parent 6be0d44 commit d39d4d3
Show file tree
Hide file tree
Showing 6 changed files with 1,547 additions and 1,049 deletions.
8 changes: 8 additions & 0 deletions autogluon/network/nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from ..space import *
from .utils import Net

from ..task.image_classification import get_model

__all__ = ['Nets']


Expand All @@ -25,6 +27,8 @@ def add_search_space(self):
cs.add_hyperparameter(net_list_hyper_param)
for net in self.net_list:
#TODO(cgraywang): distinguish between different nets, only support resnet for now
if isinstance(net, str):
net = get_model(net)
net_hyper_params = net.get_hyper_params()
conds = []
for net_hyper_param in net_hyper_params:
Expand All @@ -45,6 +49,10 @@ def get_net_strs(self):
for net in self.net_list:
if isinstance(net, Net):
net_strs.append(net.name)
elif isinstance(net, str):
net_strs.append(net)
else:
pass
return net_strs

def __repr__(self):
Expand Down
6 changes: 6 additions & 0 deletions autogluon/optim/optims.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def add_search_space(self):
cs.add_hyperparameter(optim_list_hyper_param)
for optim in self.optim_list:
# TODO: add more optims
if isinstance(optim, str):
optim = get_optim(optim)
optim_hyper_params = optim.get_hyper_params()
conds = []
for optim_hyper_param in optim_hyper_params:
Expand All @@ -42,6 +44,10 @@ def get_optim_strs(self):
for optim in self.optim_list:
if isinstance(optim, Optimizer):
optim_strs.append(optim.name)
elif isinstance(optim, str):
optim_strs.append(optim)
else:
pass
return optim_strs

def __repr__(self):
Expand Down
18 changes: 13 additions & 5 deletions autogluon/task/image_classification/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

class Results(object):
def __init__(self, model, accuracy, config):
self.model = model
self.accuracy = accuracy
self.config =config


def fit(data,
nets=Nets([
Expand Down Expand Up @@ -160,8 +166,9 @@ def _run_ray_backend(searcher, trial_scheduler):
best_result = max([trial.best_result for trial in trials])
# TODO (cgraywang)
best_config = None
results = Results(None, best_result, best_config)
logger.debug('Finished.')
return trials, best_result, cs
return results

def _run_backend(searcher, trial_scheduler):
logger.debug('Start using default backend.')
Expand Down Expand Up @@ -209,12 +216,13 @@ def _run_backend(searcher, trial_scheduler):
trials = None
best_result = trial_scheduler.get_best_reward()
best_config = trial_scheduler.get_best_config()
results = Results(None, best_result, best_config)
logger.debug('Finished.')
return trials, best_result, best_config
return results

if backend == 'ray':
result = _run_ray_backend(searcher, trial_scheduler)
results = _run_ray_backend(searcher, trial_scheduler)
else:
result = _run_backend(searcher, trial_scheduler)
results = _run_backend(searcher, trial_scheduler)
logger.debug('Finished.')
return result
return results
5 changes: 5 additions & 0 deletions autogluon/task/image_classification/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ def _read_dataset(self):
self.train_data = train_data
self.val_data = test_data

def __repr__(self):
return "AutoGluon Dataset %s" % self.__str__()

# def __str__(self):
# return "AutoGluon List Space %s: %s" % (self.name, str(self.choices))
Loading

0 comments on commit d39d4d3

Please sign in to comment.