
386
|
第
13
章
TensorFlow Extended(TFX)的一部分,TFX 是用于在生产环境中部署 TensorFlow 模型
的端到端平台。首先要使用诸如 TF Transform 之类的 TFX 组件,必须先安装它。它没
有与 TensorFlow 捆绑在一起。通过使用 TF Transform 函数进行缩放、存储等操作,你
只需定义一次预处理函数(在 Python 中)。你还可以使用所需的任何 TensorFlow 操作。
如果我们只有两个特征,则此预处理函数如下所示:
import tensorflow_transform as tft
def
preprocess(inputs): #
inputs = a batch of input features
median_age = inputs["housing_median_age"]
ocean_proximity = inputs["ocean_proximity"]
standardized_age = tft.scale_to_z_score(median_age)
ocean_proximity_id = tft.compute_and_apply_vocabulary(ocean_proximity)
return
{
"standardized_median_age": standardized_age,
"ocean_proximity_id": ocean_proximity_id
}
接下来,TF T ...