njayaram2 commented on a change in pull request #395: DL: 
madlib_keras_evaluate() function
URL: https://github.com/apache/madlib/pull/395#discussion_r289132782
 
 

 ##########
 File path: src/ports/postgres/modules/deep_learning/madlib_keras.py_in
 ##########
 @@ -546,44 +531,75 @@ def fit_final(state, **kwargs):
     return madlib_keras_serializer.serialize_weights_merge(
         image_count, weights)
 
-def evaluate1(schema_madlib, model_table, test_table, id_col, model_arch_table,
-            model_arch_id, dependent_varname, independent_varname,
-            compile_params, output_table, **kwargs):
-    # module_name = 'madlib_keras_evaluate'
-    # input_tbl_valid(test_table, module_name)
-    # input_tbl_valid(model_arch_table, module_name)
-    # output_tbl_valid(output_table, module_name)
+def get_segments_and_gpus(gpus_per_host):
+    gpus_per_host = 0 if gpus_per_host is None else gpus_per_host
+    segments_per_host = get_segments_per_host()
 
-    # _validate_input_args(test_table, model_arch_table, output_table)
+    if 0 < gpus_per_host < segments_per_host:
+        plpy.warning('The number of gpus per host is less than the number of '
+                     'segments per host. The support for this case is '
+                     'experimental and it may fail.')
 
-    model_data_query = "SELECT model_data from {0}".format(model_table)
-    model_data = plpy.execute(model_data_query)[0]['model_data']
+    return segments_per_host, gpus_per_host
 
-    model_arch_query = "SELECT model_arch, model_weights FROM {0} " \
-                       "WHERE id = {1}".format(model_arch_table, model_arch_id)
-    query_result = plpy.execute(model_arch_query)
-    if not  query_result or len(query_result) == 0:
-        plpy.error("no model arch found in table {0} with id {1}".format(
-            model_arch_table, model_arch_id))
-    query_result = query_result[0]
-    model_arch = query_result[Format.MODEL_ARCH]
+def evaluate(schema_madlib, model_table, test_table, output_table, 
gpus_per_host, **kwargs):
+    module_name = 'madlib_keras_evaluate'
+    input_validator = EvaluateInputValidator(test_table, model_table, 
output_table, module_name)
+
+    model_summary_table = input_validator.model_summary_table
+    test_summary_table = input_validator.test_summary_table
+
+    segments_per_host, gpus_per_host = get_segments_and_gpus(gpus_per_host)
+
+    model_data_query = "SELECT model_data, model_arch from 
{0}".format(model_table)
+    res = plpy.execute(model_data_query)[0]
+    model_data = res['model_data']
+    model_arch = res['model_arch']
+
+    input_shape = get_input_shape(model_arch)
+    input_validator.validate_input_shape(input_shape)
+
+    compile_params_query = "SELECT compile_params, metrics_type FROM 
{0}".format(model_summary_table)
+    res = plpy.execute(compile_params_query)[0]
+    metrics_type = res['metrics_type']
+    compile_params = res['compile_params']
     compile_params = "$madlib$" + compile_params + "$madlib$"
 
 Review comment:
   We can combine the two lines related to `compile_params` into one.

----------------------------------------------------------------
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

Reply via email to