This is an automated email from the ASF dual-hosted git repository. fmcquillan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/madlib.git
The following commit(s) were added to refs/heads/master by this push: new fd04db3 update user docs for loading model arch fd04db3 is described below commit fd04db3f96c07a865a345b3072f9d0b4c3cc5bda Author: Frank McQuillan <fmcquil...@pivotal.io> AuthorDate: Thu Mar 28 17:53:32 2019 -0700 update user docs for loading model arch --- doc/mainpage.dox.in | 8 +- .../deep_learning/keras_model_arch_table.sql_in | 224 +++++++++++++++++++-- .../utilities/minibatch_preprocessing_dl.sql_in | 3 + 3 files changed, 211 insertions(+), 24 deletions(-) diff --git a/doc/mainpage.dox.in b/doc/mainpage.dox.in index 826e8d7..e221319 100644 --- a/doc/mainpage.dox.in +++ b/doc/mainpage.dox.in @@ -287,11 +287,11 @@ Interface and implementation are subject to change. @{ @defgroup grp_cg Conjugate Gradient @defgroup grp_dl Deep Learning - @brief A collection of deep learning interfaces. - @details A collection of deep learning interfaces. + @brief A collection of modules for deep learning. + @details A collection of modules for deep learning. @{ - @defgroup grp_minibatch_preprocessing_dl Mini-Batch Preprocessor for Image Data - @defgroup grp_keras_model_arch Helper Function to Load Model Architectures to Table + @defgroup grp_keras_model_arch Load Model Architecture + @defgroup grp_minibatch_preprocessing_dl Mini-Batch Preprocessor for Images @} @defgroup grp_bayes Naive Bayes Classification @defgroup grp_sample Random Sampling diff --git a/src/ports/postgres/modules/deep_learning/keras_model_arch_table.sql_in b/src/ports/postgres/modules/deep_learning/keras_model_arch_table.sql_in index 7626107..bb734ab 100644 --- a/src/ports/postgres/modules/deep_learning/keras_model_arch_table.sql_in +++ b/src/ports/postgres/modules/deep_learning/keras_model_arch_table.sql_in @@ -30,22 +30,28 @@ m4_include(`SQLCommon.m4') /** @addtogroup grp_keras_model_arch +@brief Utility function to load model architectures and weights into a table for +use by deep learning algorithms. + <div class="toc"><b>Contents</b><ul> -<li class="level1"><a href="#load_keras_model">Helper Function to Load Model Architectures to Table</a></li> -<li class="level1"><a href="#delete_keras_model">Helper Function to Delete Model Architectures from Table</a></li> +<li class="level1"><a href="#load_keras_model">Load Model Architecture</a></li> +<li class="level1"><a href="#delete_keras_model">Delete Model Architecture</a></li> <li class="level1"><a href="#example">Examples</a></li> </ul></div> -The architecture of the model to be used in madlib_keras_train() -function must be stored in a table, the details of which must be -provided as parameters to the madlib_keras_train module. load_keras_model is -a helper function to help users insert JSON blobs of Keras model -architectures into a table. If the output table already exists, the model_arch -specified will be added as a new row into the table. The output table could thus -act as a repository of Keras model architectures. +This utility function loads model architectures and +weights into a table for use by deep learning algorithms. +Model architecture is in JSON form +and model weights are in the form of double precision arrays. +If the output table already exists, a new row is inserted +into the table so it can act as a repository for multiple model +architectures. + +There is also a utility function to delete a model architecture +from the model architecture table. -delete_keras_model can be used to delete the model architecture corresponding -to the provided model_id from the model architecture repository table (keras_model_arch_table). +@anchor load_keras_model +@par Load Model Architecture <pre class="syntax"> load_keras_model( @@ -56,17 +62,17 @@ load_keras_model( \b Arguments <dl class="arglist"> <dt>keras_model_arch_table</dt> - <dd>VARCHAR. Output table to load keras model arch. + <dd>VARCHAR. Output table to load keras model architecture. </dd> <dt>model_arch</dt> - <dd>JSON. JSON of the model architecture to insert. + <dd>JSON. JSON of the model architecture to load. </dd> </dl> <b>Output table</b> <br> - The output table produced by load_keras_model contains the following columns: + The output table contains the following columns: <table class="output"> <tr> <th>model_id</th> @@ -80,17 +86,19 @@ load_keras_model( </tr> <tr> <th>model_weights</th> - <td>DOUBLE PRECISION[]. Weights of the model for warm start. + <td>DOUBLE PRECISION[]. Weights of the model which may be use for warm start. </td> </tr> <tr> <th>__internal_madlib_id__</th> - <td>TEXT. Unique id for model arch. + <td>TEXT. Unique id for model arch. This is an id used internally be MADlib. </td> </tr> </table> </br> +@anchor delete_keras_model +@par Delete Model Architecture <pre class="syntax"> delete_keras_model( @@ -101,18 +109,194 @@ delete_keras_model( \b Arguments <dl class="arglist"> <dt>keras_model_arch_table</dt> - <dd>VARCHAR. Table containing Keras model architectures. + <dd>VARCHAR. Table containing model architectures. </dd> <dt>model_id</dt> - <dd>INTEGER. The id of the model arch to be deleted. + <dd>INTEGER. The id of the model architecture to be deleted. </dd> </dl> @anchor example @par Examples --# TBD - +-# Define or obtain model. Let's say we have a Keras model +architecture that looks like this: +<pre class="example"> +model = Sequential() +model.add(Dense(2, input_dim=3, name='dense_1')) +model.add(Dense(3, name='dense_2')) +... +model.to_json +</pre> +This is represented by the following JSON: +<pre class="example"> +'{"class_name": "Sequential", "keras_version": "2.1.6", +"config": [{"class_name": "Dense", "config": {"kernel_initializer": +{"class_name": "VarianceScaling", "config": {"distribution": "uniform", +"scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", +"kernel_constraint": null, "bias_regularizer": null, "bias_constraint": +null, "dtype": "float32", "activation": "linear", "trainable": true, +"kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", +"config": {}}, "units": 2, "batch_input_shape": [null, 3], +"use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", +"config": {"kernel_initializer": {"class_name": "VarianceScaling", +"config": {"distribution": "uniform", "scale": 1.0, "seed": null, +"mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, +"bias_regularizer": null, "bias_constraint": null, "activation": "linear", +"trainable": true, "kernel_regularizer": null, +"bias_initializer": {"class_name": "Zeros", "config": {}}, +"units": 10, "use_bias": true, "activity_regularizer": null}}], +"backend": "tensorflow"}' +</pre> +-# Load the model into the model architecture table: +<pre class="example"> +DROP TABLE IF EXISTS model_arch_library; +SELECT madlib.load_keras_model('model_arch_library', -- Output table +$$ +{"class_name": "Sequential", "keras_version": "2.1.6", +"config": [{"class_name": "Dense", "config": {"kernel_initializer": +{"class_name": "VarianceScaling", "config": {"distribution": "uniform", +"scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", +"kernel_constraint": null, "bias_regularizer": null, "bias_constraint": +null, "dtype": "float32", "activation": "linear", "trainable": true, +"kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", +"config": {}}, "units": 2, "batch_input_shape": [null, 3], +"use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", +"config": {"kernel_initializer": {"class_name": "VarianceScaling", +"config": {"distribution": "uniform", "scale": 1.0, "seed": null, +"mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, +"bias_regularizer": null, "bias_constraint": null, "activation": "linear", +"trainable": true, "kernel_regularizer": null, +"bias_initializer": {"class_name": "Zeros", "config": {}}, +"units": 10, "use_bias": true, "activity_regularizer": null}}], +"backend": "tensorflow"} +$$ ::json -- JSON blob +); +SELECT * FROM model_arch_library; +</pre> +<pre class="result"> + model_id | model_arch | model_weights | __internal_madlib_id__ +----------+-----------------------------------------------------------------------------+---------------+---------------------------------------------- + 1 | | | __madlib_temp_79462163_1553817233_28408205__ + : {"class_name": "Sequential", "keras_version": "2.1.6", + : "config": [{"class_name": "Dense", "config": {"kernel_initializer": + : {"class_name": "VarianceScaling", "config": {"distribution": "uniform", + : "scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", + : "kernel_constraint": null, "bias_regularizer": null, "bias_constraint": + : null, "dtype": "float32", "activation": "linear", "trainable": true, + : "kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", + : "config": {}}, "units": 2, "batch_input_shape": [null, 3], + : "use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", + : "config": {"kernel_initializer": {"class_name": "VarianceScaling", + : "config": {"distribution": "uniform", "scale": 1.0, "seed": null, + : "mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, + : "bias_regularizer": null, "bias_constraint": null, "activation": "linear", + : "trainable": true, "kernel_regularizer": null, + : "bias_initializer": {"class_name": "Zeros", "config": {}}, + : "units": 10, "use_bias": true, "activity_regularizer": null}}], + : "backend": "tensorflow"} + : +(1 row) +</pre> +-# Load another model into the same table: +<pre class="example"> +SELECT madlib.load_keras_model('model_arch_library', -- Output table +$$ +{"class_name": "Sequential", "keras_version": "2.1.6", +"config": [{"class_name": "Dense", "config": {"kernel_initializer": +{"class_name": "VarianceScaling", "config": {"distribution": "uniform", +"scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", +"kernel_constraint": null, "bias_regularizer": null, "bias_constraint": +null, "dtype": "float32", "activation": "linear", "trainable": true, +"kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", +"config": {}}, "units": 2, "batch_input_shape": [null, 3], +"use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", +"config": {"kernel_initializer": {"class_name": "VarianceScaling", +"config": {"distribution": "uniform", "scale": 1.0, "seed": null, +"mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, +"bias_regularizer": null, "bias_constraint": null, "activation": "linear", +"trainable": true, "kernel_regularizer": null, +"bias_initializer": {"class_name": "Zeros", "config": {}}, +"units": 10, "use_bias": true, "activity_regularizer": null}}], +"backend": "tensorflow"} +$$ ::json -- JSON blob +); +SELECT * FROM model_arch_library; +</pre> +<pre class="result"> + model_id | model_arch | model_weights | __internal_madlib_id__ +----------+-----------------------------------------------------------------------------+---------------+---------------------------------------------- + 1 | | | __madlib_temp_79462163_1553817233_28408205__ + : {"class_name": "Sequential", "keras_version": "2.1.6", + : "config": [{"class_name": "Dense", "config": {"kernel_initializer": + : {"class_name": "VarianceScaling", "config": {"distribution": "uniform", + : "scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", + : "kernel_constraint": null, "bias_regularizer": null, "bias_constraint": + : null, "dtype": "float32", "activation": "linear", "trainable": true, + : "kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", + : "config": {}}, "units": 2, "batch_input_shape": [null, 3], + : "use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", + : "config": {"kernel_initializer": {"class_name": "VarianceScaling", + : "config": {"distribution": "uniform", "scale": 1.0, "seed": null, + : "mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, + : "bias_regularizer": null, "bias_constraint": null, "activation": "linear", + : "trainable": true, "kernel_regularizer": null, + : "bias_initializer": {"class_name": "Zeros", "config": {}}, + : "units": 10, "use_bias": true, "activity_regularizer": null}}], + : "backend": "tensorflow"} + : + 2 | | | __madlib_temp_86851986_1553817356_19026896__ + : {"class_name": "Sequential", "keras_version": "2.1.6", + : "config": [{"class_name": "Dense", "config": {"kernel_initializer": + : {"class_name": "VarianceScaling", "config": {"distribution": "uniform", + : "scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", + : "kernel_constraint": null, "bias_regularizer": null, "bias_constraint": + : null, "dtype": "float32", "activation": "linear", "trainable": true, + : "kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", + : "config": {}}, "units": 2, "batch_input_shape": [null, 3], + : "use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", + : "config": {"kernel_initializer": {"class_name": "VarianceScaling", + : "config": {"distribution": "uniform", "scale": 1.0, "seed": null, + : "mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, + : "bias_regularizer": null, "bias_constraint": null, "activation": "linear", + : "trainable": true, "kernel_regularizer": null, + : "bias_initializer": {"class_name": "Zeros", "config": {}}, + : "units": 10, "use_bias": true, "activity_regularizer": null}}], + : "backend": "tensorflow"} + : +(2 rows) +</pre> +-# Delete one of the models: +<pre class="example"> +SELECT madlib.delete_keras_model('model_arch_library', -- Output table + 1 -- Model id + ); +SELECT * FROM model_arch_library; +</pre> +<pre class="result"> + model_id | model_arch | model_weights | __internal_madlib_id__ +----------+----------------------------------------------------------------------------+---------------+---------------------------------------------- + 2 | | | __madlib_temp_41851307_1553819507_11044889__ + : {"class_name": "Sequential", "keras_version": "2.1.6", + : "config": [{"class_name": "Dense", "config": {"kernel_initializer": + : {"class_name": "VarianceScaling", "config": {"distribution": "uniform", + : "scale": 1.0, "seed": null, "mode": "fan_avg"}}, "name": "dense_1", + : "kernel_constraint": null, "bias_regularizer": null, "bias_constraint": + : null, "dtype": "float32", "activation": "linear", "trainable": true, + : "kernel_regularizer": null, "bias_initializer": {"class_name": "Zeros", + : "config": {}}, "units": 2, "batch_input_shape": [null, 3], + : "use_bias": true, "activity_regularizer": null}}, {"class_name": "Dense", + : "config": {"kernel_initializer": {"class_name": "VarianceScaling", + : "config": {"distribution": "uniform", "scale": 1.0, "seed": null, + : "mode": "fan_avg"}}, "name": "new_dense", "kernel_constraint": null, + : "bias_regularizer": null, "bias_constraint": null, "activation": "linear", + : "trainable": true, "kernel_regularizer": null, + : "bias_initializer": {"class_name": "Zeros", "config": {}}, + : "units": 10, "use_bias": true, "activity_regularizer": null}}], + : "backend": "tensorflow"} + : +(1 row) +</pre> */ -- Function to add a keras model to arch table diff --git a/src/ports/postgres/modules/utilities/minibatch_preprocessing_dl.sql_in b/src/ports/postgres/modules/utilities/minibatch_preprocessing_dl.sql_in index 3be1ec0..67e216d 100644 --- a/src/ports/postgres/modules/utilities/minibatch_preprocessing_dl.sql_in +++ b/src/ports/postgres/modules/utilities/minibatch_preprocessing_dl.sql_in @@ -29,6 +29,9 @@ m4_include(`SQLCommon.m4') /** @addtogroup grp_minibatch_preprocessing_dl +@brief Utility that prepares input image data for use by models +that support mini-batch as an optimization option. + <div class="toc"><b>Contents</b><ul> <li class="level1"><a href="#minibatch_preprocessor_dl">Mini-Batch Preprocessor for Image Data</a></li> <li class="level1"><a href="#example">Examples</a></li>