njayaram2 commented on a change in pull request #399: DL: Enable transfer
learning
URL: https://github.com/apache/madlib/pull/399#discussion_r288313551
##########
File path:
src/ports/postgres/modules/deep_learning/keras_model_arch_table.py_in
##########
@@ -53,88 +53,83 @@ class Format:
arch = plpy.execute(sql)[0]
"""
- col_names = ('model_id', 'model_arch', 'model_weights',
'__internal_madlib_id__')
- col_types = ('SERIAL PRIMARY KEY', 'JSON', 'DOUBLE PRECISION[]', 'TEXT')
- (MODEL_ID, MODEL_ARCH, MODEL_WEIGHTS, __INTERNAL_MADLIB_ID__) = col_names
-
-@MinWarning("warning")
-def _execute(sql,max_rows=0):
- return plpy.execute(sql,max_rows)
-
-def load_keras_model(schema_madlib, keras_model_arch_table,
- model_arch, **kwargs):
+ col_names = ('model_id', 'model_arch', 'model_weights', 'name',
'description',
+ '__internal_madlib_id__')
+ col_types = ('SERIAL PRIMARY KEY', 'JSON', 'bytea', 'TEXT', 'TEXT', 'TEXT')
+ (MODEL_ID, MODEL_ARCH, MODEL_WEIGHTS, NAME, DESCRIPTION,
+ __INTERNAL_MADLIB_ID__) = col_names
+
+def load_keras_model(keras_model_arch_table, model_arch, model_weights,
+ name, description, **kwargs):
model_arch_table = quote_ident(keras_model_arch_table)
if not table_exists(model_arch_table):
- col_defs = get_col_name_type_sql_string(Format.col_names,
- Format.col_types)
+ col_defs = get_col_name_type_sql_string(ModelArchSchema.col_names,
+ ModelArchSchema.col_types)
sql = "CREATE TABLE {model_arch_table} ({col_defs})" \
.format(**locals())
- _execute(sql)
+ plpy.execute(sql, 0)
plpy.info("Keras Model Arch: Created new keras model arch table {0}." \
.format(model_arch_table))
else:
missing_cols = columns_missing_from_table(model_arch_table,
- Format.col_names)
+ ModelArchSchema.col_names)
if len(missing_cols) > 0:
plpy.error("Keras Model Arch: Invalid keras model arch table {0},"
" missing columns: {1}".format(model_arch_table,
missing_cols))
unique_str = unique_string(prefix_has_temp=False)
-
- sql = """INSERT INTO {model_arch_table} ({model_arch_col},
{internal_id_col})
- VALUES({model_arch}, '{unique_str}');
- SELECT {model_id_col}, {model_arch_col}
- FROM {model_arch_table} WHERE {internal_id_col} =
'{unique_str}'
- """.format(model_arch_table=model_arch_table,
- model_arch_col=Format.MODEL_ARCH,
- unique_str=unique_str,
- model_arch=quote_literal(model_arch),
- model_id_col=Format.MODEL_ID,
- internal_id_col=Format.__INTERNAL_MADLIB_ID__)
- res = _execute(sql,1)
-
- if len(res) != 1 or res[0][Format.MODEL_ARCH] != model_arch:
+ insert_query = plpy.prepare("INSERT INTO {model_arch_table} "
+ "VALUES(DEFAULT, $1, $2, $3, $4,
$5);".format(**locals()),
+ ModelArchSchema.col_types[1:])
+ insert_res = plpy.execute(insert_query,[model_arch, model_weights, name,
description,
+ unique_str], 0)
+
+ select_query = "SELECT {model_id_col}, {model_arch_col} FROM
{model_arch_table} " \
+ "WHERE {internal_id_col} = '{unique_str}'".format(
+ model_id_col=ModelArchSchema.MODEL_ID,
Review comment:
Is there a specific reason why the query string is not within a pair of
`"""`? IMO query string inside `""" query string formatted into multiple lines
"""` is a lot more easier to read instead of having multiple lines with `\`.
----------------------------------------------------------------
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