Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shreyan Chowdhury
moodwalk
Commits
5a5a798c
Commit
5a5a798c
authored
Sep 10, 2019
by
Shreyan Chowdhury
Browse files
add config functionality in command line
parent
cc057fed
Changes
1
Hide whitespace changes
Inline
Side-by-side
experiments/experiment_baseline.py
View file @
5a5a798c
...
...
@@ -4,14 +4,31 @@ from pytorch_lightning import Trainer
from
test_tube
import
Experiment
,
HyperOptArgumentParser
from
models.baseline
import
CNN
as
Network
config
=
{
'epochs'
:
1
}
def
epochs_500
():
global
config
config
[
'epochs'
]
=
500
def
run
(
hparams
):
init_experiment
(
comment
=
hparams
.
experiment_name
)
from
utils
import
CURR_RUN_PATH
,
logger
# import these after init_experiment
logger
.
info
(
CURR_RUN_PATH
)
logger
.
info
(
f
"tensorboard --logdir=
{
CURR_RUN_PATH
}
"
)
exp
=
Experiment
(
save_dir
=
CURR_RUN_PATH
)
def
setup_config
():
conf
=
hparams
.
config
conf_func
=
globals
()[
conf
]
try
:
conf_func
()
except
:
logger
.
error
(
f
"Config
{
conf
}
not defined"
)
setup_config
()
global
config
# parameters used in the baseline (read from main.py and solver.py)
# n_epochs = 500
# lr = 1e-4
...
...
@@ -20,7 +37,7 @@ def run(hparams):
if
USE_GPU
:
trainer
=
Trainer
(
gpus
=
[
0
],
distributed_backend
=
'ddp'
,
experiment
=
exp
,
max_nb_epochs
=
1
,
train_percent_check
=
1.0
,
experiment
=
exp
,
max_nb_epochs
=
config
[
'epochs'
]
,
train_percent_check
=
hparams
.
train_percent
,
fast_dev_run
=
False
)
else
:
trainer
=
Trainer
(
experiment
=
exp
,
max_nb_epochs
=
1
,
train_percent_check
=
0.01
,
...
...
@@ -38,6 +55,11 @@ if __name__=='__main__':
parent_parser
=
HyperOptArgumentParser
(
strategy
=
'grid_search'
,
add_help
=
False
)
parent_parser
.
add_argument
(
'--experiment_name'
,
type
=
str
,
default
=
'pt_lightning_exp_a'
,
help
=
'test tube exp name'
)
parent_parser
.
add_argument
(
'--config'
,
type
=
str
,
help
=
'config function to run'
)
#TODO : multiple arguments for --config using nargs='+' is not working with the test_tube
# implementation of argument parser
parent_parser
.
add_argument
(
'--train_percent'
,
type
=
float
,
default
=
1.0
,
help
=
'how much train data to use'
)
parser
=
Network
.
add_model_specific_args
(
parent_parser
)
hyperparams
=
parser
.
parse_args
()
run
(
hyperparams
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment