如何在datalab上导出tensorflow模型以用于bigquery?

如何在datalab上导出tensorflow模型以用于bigquery?,tensorflow,google-bigquery,google-cloud-datalab,Tensorflow,Google Bigquery,Google Cloud Datalab,我在谷歌云数据实验室有一个TensorFlow的训练有素的模型。 我想将其导出并导入到BigQuery中,然后使用BigQuery进行预测。如何使用路径导出它为gs://*?如果您使用的是TensorFlow 1.14或更高版本和Keras,那么: tf.saved_model.save(model, 'gs://bucket/dir') 请参见如果您使用的是TensorFlow 1.14或更高版本和Keras,则: tf.saved_model.save(model, 'gs://buc

我在谷歌云数据实验室有一个TensorFlow的训练有素的模型。
我想将其导出并导入到BigQuery中,然后使用BigQuery进行预测。如何使用路径导出它为
gs://*

如果您使用的是TensorFlow 1.14或更高版本和Keras,那么:

tf.saved_model.save(model,  'gs://bucket/dir')

请参见

如果您使用的是TensorFlow 1.14或更高版本和Keras,则:

tf.saved_model.save(model,  'gs://bucket/dir')

请参见

如果您有使用TensorFlow早期版本编写的代码,它可能使用Estimator API。在这种情况下,请使用:

estimator.export_savedmodel('gs://bucket/dir', serving_input_fn)
如果必须使用占位符定义服务功能,则模型的每个输入对应一个占位符:

def serving_input_fn():
    feature_placeholders = {
        'input1': tf.placeholder(tf.string, [None]),
        'input2': tf.placeholder(tf.float32, [None]),
    }
    features = {
        key: tf.expand_dims(tensor, -1)
        for key, tensor in feature_placeholders.items()
    }
    return tf.estimator.export.ServingInputReceiver(features, feature_placeholders)

如果您有使用TensorFlow早期版本编写的代码,它可能会使用Estimator API。在这种情况下,请使用:

estimator.export_savedmodel('gs://bucket/dir', serving_input_fn)
如果必须使用占位符定义服务功能,则模型的每个输入对应一个占位符:

def serving_input_fn():
    feature_placeholders = {
        'input1': tf.placeholder(tf.string, [None]),
        'input2': tf.placeholder(tf.float32, [None]),
    }
    features = {
        key: tf.expand_dims(tensor, -1)
        for key, tensor in feature_placeholders.items()
    }
    return tf.estimator.export.ServingInputReceiver(features, feature_placeholders)