Skip to content

Commit

Permalink
Specify myconfig in training (autorope#997)
Browse files Browse the repository at this point in the history
* Adding support for specifying own myconfig.py file in donkey train and small refactorings

* Update version after rebase from main
  • Loading branch information
DocGarbanzo authored Apr 4, 2022
1 parent d0ad870 commit 4a20c18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
16 changes: 6 additions & 10 deletions donkeycar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"""
import os
import types
from logging import getLogger

logger = getLogger(__name__)


class Config:
Expand Down Expand Up @@ -51,25 +54,18 @@ def load_config(config_path=None, myconfig="myconfig.py"):
if os.path.exists(local_config):
config_path = local_config

print('loading config file: {}'.format(config_path))
logger.info(f'loading config file: {config_path}')
cfg = Config()
cfg.from_pyfile(config_path)

# look for the optional myconfig.py in the same path.
personal_cfg_path = config_path.replace("config.py", myconfig)
if os.path.exists(personal_cfg_path):
print("loading personal config over-rides from", myconfig)
logger.info(f"loading personal config over-rides from {myconfig}")
personal_cfg = Config()
personal_cfg.from_pyfile(personal_cfg_path)
cfg.from_object(personal_cfg)
else:
print("personal config: file not found ", personal_cfg_path)

# derived settings
if hasattr(cfg, 'IMAGE_H') and hasattr(cfg, 'IMAGE_W'):
cfg.TARGET_H = cfg.IMAGE_H
cfg.TARGET_W = cfg.IMAGE_W
if hasattr(cfg, 'IMAGE_DEPTH'):
cfg.TARGET_D = cfg.IMAGE_DEPTH
logger.warning(f"personal config: file not found {personal_cfg_path}")

return cfg
25 changes: 12 additions & 13 deletions donkeycar/management/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@ def make_dir(path):
return real_path


def load_config(config_path):

'''
def load_config(config_path, myconfig='myconfig.py'):
"""
load a config from the given path
'''
"""
conf = os.path.expanduser(config_path)

if not os.path.exists(conf):
print("No config file at location: %s. Add --config to specify\
location or run from dir containing config.py." % conf)
logger.error(f"No config file at location: {conf}. Add --config to "
f"specify location or run from dir containing config.py.")
return None

try:
cfg = dk.load_config(conf)
except:
print("Exception while loading config from", conf)
cfg = dk.load_config(conf, myconfig)
except Exception as e:
logger.error(f"Exception {e} while loading config from {conf}")
return None

return cfg
Expand Down Expand Up @@ -541,7 +539,8 @@ def parse_args(self, args):
def run(self, args):
args = self.parse_args(args)
args.tub = ','.join(args.tub)
cfg = load_config(args.config)
my_cfg = args.myconfig
cfg = load_config(args.config, my_cfg)
framework = args.framework if args.framework \
else getattr(cfg, 'DEFAULT_AI_FRAMEWORK', 'tensorflow')

Expand All @@ -554,8 +553,8 @@ def run(self, args):
train(cfg, args.tub, args.model, args.type,
checkpoint_path=args.checkpoint)
else:
print(f"Unrecognized framework: {framework}. Please specify one of "
f"'tensorflow' or 'pytorch'")
logger.error(f"Unrecognized framework: {framework}. Please specify "
f"one of 'tensorflow' or 'pytorch'")


class ModelDatabase(BaseCommand):
Expand Down
2 changes: 1 addition & 1 deletion scripts/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def profile(model_path, model_type):
model = dk.utils.get_model_by_type(model_type, cfg)
model.load(model_path)

h, w, ch = cfg.TARGET_H, cfg.TARGET_W, cfg.TARGET_D
h, w, ch = cfg.IMAGE_H, cfg.IMAGE_W, cfg.IMAGE_DEPTH

# generate random array in the right shape in [0,1)
img = np.random.randint(0, 255, size=(h, w, ch))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def package_files(directory, strip_leading):
long_description = fh.read()

setup(name='donkeycar',
version="4.3.8",
version="4.3.9",
long_description=long_description,
description='Self driving library for python.',
url='https://github.com/autorope/donkeycar',
Expand Down

0 comments on commit 4a20c18

Please sign in to comment.