kaknikhil commented on a change in pull request #443: DL: Add training for 
multiple models
URL: https://github.com/apache/madlib/pull/443#discussion_r327368412
 
 

 ##########
 File path: 
src/ports/postgres/modules/deep_learning/madlib_keras_fit_multiple_model.py_in
 ##########
 @@ -0,0 +1,489 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import plpy
+import time
+import sys
+
+from keras.models import *
+from madlib_keras import compute_loss_and_metrics
+from madlib_keras import get_initial_weights
+from madlib_keras import get_model_arch_weights
+from madlib_keras import get_segments_and_gpus
+from madlib_keras import get_source_summary_table_dict
+from madlib_keras_helper import *
+from madlib_keras_model_selection import ModelSelectionSchema
+from madlib_keras_validator import *
+from madlib_keras_wrapper import *
+
+from utilities.control import MinWarning
+from utilities.control import OptimizerControl
+from utilities.utilities import unique_string
+from utilities.utilities import add_postfix
+from utilities.utilities import rotate
+from utilities.utilities import madlib_version
+from utilities.utilities import is_platform_pg
+import json
+from collections import defaultdict
+import random
+import datetime
+mb_dep_var_col = MINIBATCH_OUTPUT_DEPENDENT_COLNAME_DL
+mb_indep_var_col = MINIBATCH_OUTPUT_INDEPENDENT_COLNAME_DL
+dist_key_col = DISTRIBUTION_KEY_COLNAME
+
+
+@MinWarning("warning")
+class FitMultipleModel():
+    def __init__(self, schema_madlib, source_table, model_output_table,
+                 model_selection_table, num_iterations,
+                 gpus_per_host=0, validation_table=None, **kwargs):
+        # set the random seed for visit order/scheduling
+        random.seed(1)
+        if is_platform_pg():
+            plpy.error(
+                "DL: Multiple model training is not supported on PostgreSQL.")
+        self.source_table = source_table
+        self.validation_table = validation_table
+        self.model_selection_table = model_selection_table
+        if self.model_selection_table:
+            self.model_selection_summary_table = 
add_postfix(self.model_selection_table, '_summary')
+        self.model_output_table = model_output_table
+        if self.model_output_table:
+            self.model_info_table = add_postfix(model_output_table, '_info')
+            self.model_summary_table = add_postfix(
+                model_output_table, '_summary')
+        self.num_iterations = num_iterations
+        self.module_name = 'madlib_keras_fit_multiple_model'
+        self.schema_madlib = schema_madlib
+        self.version = madlib_version(self.schema_madlib)
+        self.mst_key_col = ModelSelectionSchema.MST_KEY
+        self.model_id_col = ModelSelectionSchema.MODEL_ID
+        self.compile_params_col = ModelSelectionSchema.COMPILE_PARAMS
+        self.fit_params_col = ModelSelectionSchema.FIT_PARAMS
+        self.model_arch_table_col = ModelSelectionSchema.MODEL_ARCH_TABLE
+        self.model_weights_col=ModelArchSchema.MODEL_WEIGHTS
+        self.model_arch_col=ModelArchSchema.MODEL_ARCH
+        self.train_mst_metric_eval_time = defaultdict(list)
+        self.train_mst_loss = defaultdict(list)
+        self.train_mst_metric = defaultdict(list)
+        self.info_str = ""
+        self.seg_ids_train, self.images_per_seg_train = \
+            get_image_count_per_seg_for_minibatched_data_from_db(
+                self.source_table)
+        input_tbl_valid(self.model_selection_table, self.module_name)
+        input_tbl_valid(self.model_selection_summary_table, self.module_name,
+                        error_suffix_str="Please ensure that the model 
selection table ({0}) "
+                                         "has been created by "
+                                         
"load_model_selection_table().".format(self.model_selection_table))
+        self.msts, self.model_arch_table = self.query_model_configs()
+        self.dep_shape_col = add_postfix(mb_dep_var_col, "_shape")
+        self.ind_shape_col = add_postfix(mb_indep_var_col, "_shape")
+        self.fit_validator_train = FitMultipleInputValidator(
+            self.source_table, self.validation_table, self.model_output_table,
+            self.model_arch_table, mb_dep_var_col, mb_indep_var_col,
+            self.num_iterations, 1, False)
+
 
 Review comment:
   madlib_keras_fit validates that the input shape of the model arch is the 
same as the input shape of the independent_var. See 
https://github.com/apache/madlib/blob/dae72a0c3a4bf3ba9ac3837c51190932e1d62ba3/src/ports/postgres/modules/deep_learning/madlib_keras.py_in#L88
   
   We should do this in keras_fit_multiple as well. 

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