kaknikhil commented on a change in pull request #372: DL: Trap unsupported
options for compile and fit params
URL: https://github.com/apache/madlib/pull/372#discussion_r279022582
##########
File path: src/ports/postgres/modules/deep_learning/madlib_keras_wrapper.py_in
##########
@@ -199,7 +215,34 @@ def get_optimizers():
def compile_model(model, compile_params):
optimizers = get_optimizers()
(opt_name,final_args,compile_dict) = parse_compile_params(compile_params)
- optimizer = optimizers[opt_name](**final_args) if final_args else opt_name
- model.compile(optimizer=optimizer,
- loss=compile_dict['loss'],
- metrics=compile_dict['metrics'])
+ compile_dict['optimizer'] = optimizers[opt_name](**final_args) if
final_args else opt_name
+ validate_compile_params(compile_dict)
+ model.compile(**compile_dict)
+
+def validate_compile_params(compile_dict):
+ _assert(compile_dict['metrics'] is None or type(compile_dict['metrics'])
is list,
+ "wrong input type for compile parameter metrics: multi-output
model"
+ "is not supported yet, please pass a list")
+
+ _assert(compile_dict['loss_weights'] is None or
+ type(compile_dict['loss_weights']) is list or
+ type(compile_dict['loss_weights']) is dict,
+ "wrong input type for compile parameter loss_weights: only list "
+ "and dictionary are supported for now")
+ _assert(compile_dict['weighted_metrics'] is None or
+ type(compile_dict['weighted_metrics']) is list,
+ "wrong input type for compile parameter weighted_metrics: only
list "
+ "is supported for now")
+
+ _assert(compile_dict['sample_weight_mode'] is None or
+ compile_dict['sample_weight_mode'] == "temporal",
+ """compile parameter sample_weight_mode can only be "temporal" or
None {0}
+ """.format(compile_dict['sample_weight_mode']))
+
+ accepted_compile_params = ['optimizer', 'loss', 'metrics', 'loss_weights',
+ 'weighted_metrics', 'sample_weight_mode']
+ for ckey in compile_dict.keys():
+ _assert(ckey in accepted_compile_params,
+ "{0} is not accepted as a compile parameter yet.".format(ckey))
Review comment:
Maybe we should also prompt the user to review the dl docs
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services