此页面由 Cloud Translation API 翻译。
Switch to English

与TensorFlow预处理数据变换

TensorFlow的特征工程组件扩展(TFX)

此示例colab笔记本提供了如何稍微更高级的例子TensorFlow变换tf.Transform )使用完全相同两个训练模型和生产服务推论相同的代码可以被用来预处理数据。

TensorFlow变换是预处理输入数据TensorFlow,包括创建需要全传过来的训练数据集的特征库。例如,使用TensorFlow变换你可以:

  • 通过使用平均值和标准偏差归一化的输入值
  • 通过在所有输入值中产生的词汇字符串转换成整数
  • 转换将它们分配到桶漂浮到整数,基于观测数据分布

TensorFlow内置了用于在一个单一的实施例或一批次的实施例的操作的支持。 tf.Transform扩展这些功能可支持全越过整个训练数据集。

的输出tf.Transform导出为TensorFlow图,你可以使用培训和服务。使用针对训练相同的图形和服务可以防止歪斜,因为相同的变换在两个阶段应用。

我们正在做在这个例子中

在这个例子中,我们将处理一个广泛使用的包含数据集的人口普查数据 ,并培养了模型进行分类。一路上,我们将使用可转换数据tf.Transform

Python的检查,进口,和全局

首先,我们将确保我们使用Python 3,然后继续前进,安装并导入我们需要的东西。

 import sys

# Confirm that we're using Python 3
assert sys.version_info.major is 3, 'Oops, not running Python 3. Use Runtime > Change runtime type'
 
 import os
import pprint

import tensorflow as tf
print('TF: {}'.format(tf.__version__))

print('Installing Apache Beam')
!pip install -Uq apache_beam==2.21.0
import apache_beam as beam
print('Beam: {}'.format(beam.__version__))

print('Installing TensorFlow Transform')
!pip install -q tensorflow-transform==0.22.0
import tensorflow_transform as tft
print('Transform: {}'.format(tft.__version__))

import tensorflow_transform.beam as tft_beam

!wget https://storage.googleapis.com/artifacts.tfx-oss-public.appspot.com/datasets/census/adult.data
!wget https://storage.googleapis.com/artifacts.tfx-oss-public.appspot.com/datasets/census/adult.test

train = './adult.data'
test = './adult.test'
 
TF: 2.2.0
Installing Apache Beam
Beam: 2.21.0
Installing TensorFlow Transform
Transform: 0.22.0
--2020-07-27 09:13:34--  https://storage.googleapis.com/artifacts.tfx-oss-public.appspot.com/datasets/census/adult.data
Resolving storage.googleapis.com (storage.googleapis.com)... 64.233.187.128, 74.125.203.128, 74.125.23.128, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|64.233.187.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3974305 (3.8M) [application/octet-stream]
Saving to: ‘adult.data’

adult.data          100%[===================>]   3.79M  --.-KB/s    in 0.02s   

2020-07-27 09:13:34 (244 MB/s) - ‘adult.data’ saved [3974305/3974305]

--2020-07-27 09:13:34--  https://storage.googleapis.com/artifacts.tfx-oss-public.appspot.com/datasets/census/adult.test
Resolving storage.googleapis.com (storage.googleapis.com)... 64.233.187.128, 74.125.203.128, 74.125.23.128, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|64.233.187.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2003153 (1.9M) [application/octet-stream]
Saving to: ‘adult.test’

adult.test          100%[===================>]   1.91M  --.-KB/s    in 0.02s   

2020-07-27 09:13:35 (107 MB/s) - ‘adult.test’ saved [2003153/2003153]


我们命名列

我们将在我们的数据引用的列上创建一些方便的名单。

 CATEGORICAL_FEATURE_KEYS = [
    'workclass',
    'education',
    'marital-status',
    'occupation',
    'relationship',
    'race',
    'sex',
    'native-country',
]
NUMERIC_FEATURE_KEYS = [
    'age',
    'capital-gain',
    'capital-loss',
    'hours-per-week',
]
OPTIONAL_NUMERIC_FEATURE_KEYS = [
    'education-num',
]
LABEL_KEY = 'label'
 

定义我们的特色和模式

让我们来定义基础上,列在我们输入什么类型的模式。别的不说,这将有正确导入帮助他们。

 RAW_DATA_FEATURE_SPEC = dict(
    [(name, tf.io.FixedLenFeature([], tf.string))
     for name in CATEGORICAL_FEATURE_KEYS] +
    [(name, tf.io.FixedLenFeature([], tf.float32))
     for name in NUMERIC_FEATURE_KEYS] +
    [(name, tf.io.VarLenFeature(tf.float32))
     for name in OPTIONAL_NUMERIC_FEATURE_KEYS] +
    [(LABEL_KEY, tf.io.FixedLenFeature([], tf.string))]
)

RAW_DATA_METADATA = tft.tf_metadata.dataset_metadata.DatasetMetadata(
    tft.tf_metadata.dataset_schema.schema_utils.schema_from_feature_spec(RAW_DATA_FEATURE_SPEC))
 

设置超参数和基本管理操作

常量和超参数用于训练。桶大小包括数据集中的描述列出的所有类别,以及一个额外的“?”它代表未知。

 testing = os.getenv("WEB_TEST_BROWSER", False)
if testing:
  TRAIN_NUM_EPOCHS = 1
  NUM_TRAIN_INSTANCES = 1
  TRAIN_BATCH_SIZE = 1
  NUM_TEST_INSTANCES = 1
else:
  TRAIN_NUM_EPOCHS = 16
  NUM_TRAIN_INSTANCES = 32561
  TRAIN_BATCH_SIZE = 128
  NUM_TEST_INSTANCES = 16281

# Names of temp files
TRANSFORMED_TRAIN_DATA_FILEBASE = 'train_transformed'
TRANSFORMED_TEST_DATA_FILEBASE = 'test_transformed'
EXPORTED_MODEL_DIR = 'exported_model_dir'
 

清洁的

创建光束转换为清洁我们的输入数据

我们将创建一个梁变换通过创建阿帕奇Beam的子类PTransform类并覆盖expand方法来指定实际的处理逻辑。一个PTransform代表数据处理操作,或一步,在您的管道。每PTransform接受一个或多个PCollection对象作为输入,执行的处理功能,你提供关于的元素PCollection ,并产生零个或多个输出PCollection对象。

我们的转换类将适用Beam的ParDo输入PCollection包含我们的人口普查数据集,在输出端产生干净的数据PCollection

 class MapAndFilterErrors(beam.PTransform):
  """Like beam.Map but filters out errors in the map_fn."""

  class _MapAndFilterErrorsDoFn(beam.DoFn):
    """Count the bad examples using a beam metric."""

    def __init__(self, fn):
      self._fn = fn
      # Create a counter to measure number of bad elements.
      self._bad_elements_counter = beam.metrics.Metrics.counter(
          'census_example', 'bad_elements')

    def process(self, element):
      try:
        yield self._fn(element)
      except Exception:  # pylint: disable=broad-except
        # Catch any exception the above call.
        self._bad_elements_counter.inc(1)

  def __init__(self, fn):
    self._fn = fn

  def expand(self, pcoll):
    return pcoll | beam.ParDo(self._MapAndFilterErrorsDoFn(self._fn))
 

与预处理tf.Transform

创建tf.Transform preprocessing_fn

预处理功能是tf.Transform的最重要的概念。预处理功能就是数据集的转变真的发生。它接受并返回张量的一个字典,其中张量表示TensorSparseTensor 。有API调用,通常形成预处理功能的心脏分为两大类:

  1. TensorFlow行动:接受并返回张量,这通常意味着TensorFlow OPS任何函数。这些加载TensorFlow操作的图表,在一个时间变换原始数据转换为变换后的数据的一个特征向量。这些都将培训和服务过程中的每一个运行的例子。
  2. TensorFlow变换分析仪:任何由tf.Transform提供的分析仪。分析仪接受和返回张量,但不像TensorFlow OPS他们只训练期间运行一次,并且一般做一个全面检查在整个训练数据集。他们创建张量常数 ,它被添加到您的图表。例如, tft.min计算最小的张量在训练数据集。 tf.Transform提供一组固定的分析仪,但是这将在未来版本中进行扩展。
 def preprocessing_fn(inputs):
  """Preprocess input columns into transformed columns."""
  # Since we are modifying some features and leaving others unchanged, we
  # start by setting `outputs` to a copy of `inputs.
  outputs = inputs.copy()

  # Scale numeric columns to have range [0, 1].
  for key in NUMERIC_FEATURE_KEYS:
    outputs[key] = tft.scale_to_0_1(outputs[key])

  for key in OPTIONAL_NUMERIC_FEATURE_KEYS:
    # This is a SparseTensor because it is optional. Here we fill in a default
    # value when it is missing.
    sparse = tf.sparse.SparseTensor(outputs[key].indices, outputs[key].values,
                                    [outputs[key].dense_shape[0], 1])
    dense = tf.sparse.to_dense(sp_input=sparse, default_value=0.)
    # Reshaping from a batch of vectors of size 1 to a batch to scalars.
    dense = tf.squeeze(dense, axis=1)
    outputs[key] = tft.scale_to_0_1(dense)

  # For all categorical columns except the label column, we generate a
  # vocabulary but do not modify the feature.  This vocabulary is instead
  # used in the trainer, by means of a feature column, to convert the feature
  # from a string to an integer id.
  for key in CATEGORICAL_FEATURE_KEYS:
    tft.vocabulary(inputs[key], vocab_filename=key)

  # For the label column we provide the mapping from string to index.
  table_keys = ['>50K', '<=50K']
  initializer = tf.lookup.KeyValueTensorInitializer(
      keys=table_keys,
      values=tf.cast(tf.range(len(table_keys)), tf.int64),
      key_dtype=tf.string,
      value_dtype=tf.int64)
  table = tf.lookup.StaticHashTable(initializer, default_value=-1)
  outputs[LABEL_KEY] = table.lookup(outputs[LABEL_KEY])

  return outputs
 

转换数据

现在,我们已经准备好开始在Apache梁管道改造我们的数据。

  1. 读取的数据使用CSV阅读器
  2. 使用我们的新清洁它MapAndFilterErrors变换
  3. 改造它采用预处理流水线尺度数值数据,并将其转换从字符串到Int64值指数分类数据,为每个类别创建词汇
  4. 写出来的结果作为TFRecordExample PROTOS,我们将用于以后的训练模型
 def transform_data(train_data_file, test_data_file, working_dir):
  """Transform the data and write out as a TFRecord of Example protos.

  Read in the data using the CSV reader, and transform it using a
  preprocessing pipeline that scales numeric data and converts categorical data
  from strings to int64 values indices, by creating a vocabulary for each
  category.

  Args:
    train_data_file: File containing training data
    test_data_file: File containing test data
    working_dir: Directory to write transformed data and metadata to
  """

  # The "with" block will create a pipeline, and run that pipeline at the exit
  # of the block.
  with beam.Pipeline() as pipeline:
    with tft_beam.Context(temp_dir=tempfile.mkdtemp()):
      # Create a coder to read the census data with the schema.  To do this we
      # need to list all columns in order since the schema doesn't specify the
      # order of columns in the csv.
      ordered_columns = [
          'age', 'workclass', 'fnlwgt', 'education', 'education-num',
          'marital-status', 'occupation', 'relationship', 'race', 'sex',
          'capital-gain', 'capital-loss', 'hours-per-week', 'native-country',
          'label'
      ]
      converter = tft.coders.CsvCoder(ordered_columns, RAW_DATA_METADATA.schema)

      # Read in raw data and convert using CSV converter.  Note that we apply
      # some Beam transformations here, which will not be encoded in the TF
      # graph since we don't do them from within tf.Transform's methods
      # (AnalyzeDataset, TransformDataset etc.).  These transformations are just
      # to get data into a format that the CSV converter can read, in particular
      # removing spaces after commas.
      #
      # We use MapAndFilterErrors instead of Map to filter out decode errors in
      # convert.decode which should only occur for the trailing blank line.
      raw_data = (
          pipeline
          | 'ReadTrainData' >> beam.io.ReadFromText(train_data_file)
          | 'FixCommasTrainData' >> beam.Map(
              lambda line: line.replace(', ', ','))
          | 'DecodeTrainData' >> MapAndFilterErrors(converter.decode))

      # Combine data and schema into a dataset tuple.  Note that we already used
      # the schema to read the CSV data, but we also need it to interpret
      # raw_data.
      raw_dataset = (raw_data, RAW_DATA_METADATA)
      transformed_dataset, transform_fn = (
          raw_dataset | tft_beam.AnalyzeAndTransformDataset(preprocessing_fn))
      transformed_data, transformed_metadata = transformed_dataset
      transformed_data_coder = tft.coders.ExampleProtoCoder(
          transformed_metadata.schema)

      _ = (
          transformed_data
          | 'EncodeTrainData' >> beam.Map(transformed_data_coder.encode)
          | 'WriteTrainData' >> beam.io.WriteToTFRecord(
              os.path.join(working_dir, TRANSFORMED_TRAIN_DATA_FILEBASE)))

      # Now apply transform function to test data.  In this case we remove the
      # trailing period at the end of each line, and also ignore the header line
      # that is present in the test data file.
      raw_test_data = (
          pipeline
          | 'ReadTestData' >> beam.io.ReadFromText(test_data_file,
                                                   skip_header_lines=1)
          | 'FixCommasTestData' >> beam.Map(
              lambda line: line.replace(', ', ','))
          | 'RemoveTrailingPeriodsTestData' >> beam.Map(lambda line: line[:-1])
          | 'DecodeTestData' >> MapAndFilterErrors(converter.decode))

      raw_test_dataset = (raw_test_data, RAW_DATA_METADATA)

      transformed_test_dataset = (
          (raw_test_dataset, transform_fn) | tft_beam.TransformDataset())
      # Don't need transformed data schema, it's the same as before.
      transformed_test_data, _ = transformed_test_dataset

      _ = (
          transformed_test_data
          | 'EncodeTestData' >> beam.Map(transformed_data_coder.encode)
          | 'WriteTestData' >> beam.io.WriteToTFRecord(
              os.path.join(working_dir, TRANSFORMED_TEST_DATA_FILEBASE)))

      # Will write a SavedModel and metadata to working_dir, which can then
      # be read by the tft.TFTransformOutput class.
      _ = (
          transform_fn
          | 'WriteTransformFn' >> tft_beam.WriteTransformFn(working_dir))
 

使用我们的预处理数据来训练模型

为了展示tf.Transform使我们能够使用相同的代码进行培训和服务,从而防止歪斜,我们要培养的模式。要培养我们的模型,并准备我们的训练模型进行生产,我们需要创建输入功能。我们的训练输入功能和我们的服务输入功能之间的主要区别是,训练数据中包含的标签和生产数据则不会。参数和收益也有所区别。

创建训练输入功能

 def _make_training_input_fn(tf_transform_output, transformed_examples,
                            batch_size):
  """Creates an input function reading from transformed data.

  Args:
    tf_transform_output: Wrapper around output of tf.Transform.
    transformed_examples: Base filename of examples.
    batch_size: Batch size.

  Returns:
    The input function for training or eval.
  """
  def input_fn():
    """Input function for training and eval."""
    dataset = tf.data.experimental.make_batched_features_dataset(
        file_pattern=transformed_examples,
        batch_size=batch_size,
        features=tf_transform_output.transformed_feature_spec(),
        reader=tf.data.TFRecordDataset,
        shuffle=True)

    transformed_features = tf.compat.v1.data.make_one_shot_iterator(
        dataset).get_next()

    # Extract features and label from the transformed tensors.
    transformed_labels = transformed_features.pop(LABEL_KEY)

    return transformed_features, transformed_labels

  return input_fn
 

创建服务输入功能

让我们创建一个输入功能,我们可以在生产中使用,并准备我们的训练模型的服务。

 def _make_serving_input_fn(tf_transform_output):
  """Creates an input function reading from raw data.

  Args:
    tf_transform_output: Wrapper around output of tf.Transform.

  Returns:
    The serving input function.
  """
  raw_feature_spec = RAW_DATA_FEATURE_SPEC.copy()
  # Remove label since it is not available during serving.
  raw_feature_spec.pop(LABEL_KEY)

  def serving_input_fn():
    """Input function for serving."""
    # Get raw features by generating the basic serving input_fn and calling it.
    # Here we generate an input_fn that expects a parsed Example proto to be fed
    # to the model at serving time.  See also
    # tf.estimator.export.build_raw_serving_input_receiver_fn.
    raw_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
        raw_feature_spec, default_batch_size=None)
    serving_input_receiver = raw_input_fn()

    # Apply the transform function that was used to generate the materialized
    # data.
    raw_features = serving_input_receiver.features
    transformed_features = tf_transform_output.transform_raw_features(
        raw_features)

    return tf.estimator.export.ServingInputReceiver(
        transformed_features, serving_input_receiver.receiver_tensors)

  return serving_input_fn
 

裹在FeatureColumns我们的输入数据

我们的模式会想到我们在TensorFlow FeatureColumns数据。

 def get_feature_columns(tf_transform_output):
  """Returns the FeatureColumns for the model.

  Args:
    tf_transform_output: A `TFTransformOutput` object.

  Returns:
    A list of FeatureColumns.
  """
  # Wrap scalars as real valued columns.
  real_valued_columns = [tf.feature_column.numeric_column(key, shape=())
                         for key in NUMERIC_FEATURE_KEYS]

  # Wrap categorical columns.
  one_hot_columns = [
      tf.feature_column.categorical_column_with_vocabulary_file(
          key=key,
          vocabulary_file=tf_transform_output.vocabulary_file_by_name(
              vocab_filename=key))
      for key in CATEGORICAL_FEATURE_KEYS]

  return real_valued_columns + one_hot_columns
 

火车,评估和出口我们的模型

 def train_and_evaluate(working_dir, num_train_instances=NUM_TRAIN_INSTANCES,
                       num_test_instances=NUM_TEST_INSTANCES):
  """Train the model on training data and evaluate on test data.

  Args:
    working_dir: Directory to read transformed data and metadata from and to
        write exported model to.
    num_train_instances: Number of instances in train set
    num_test_instances: Number of instances in test set

  Returns:
    The results from the estimator's 'evaluate' method
  """
  tf_transform_output = tft.TFTransformOutput(working_dir)

  run_config = tf.estimator.RunConfig()

  estimator = tf.estimator.LinearClassifier(
      feature_columns=get_feature_columns(tf_transform_output),
      config=run_config,
      loss_reduction=tf.losses.Reduction.SUM)

  # Fit the model using the default optimizer.
  train_input_fn = _make_training_input_fn(
      tf_transform_output,
      os.path.join(working_dir, TRANSFORMED_TRAIN_DATA_FILEBASE + '*'),
      batch_size=TRAIN_BATCH_SIZE)
  estimator.train(
      input_fn=train_input_fn,
      max_steps=TRAIN_NUM_EPOCHS * num_train_instances / TRAIN_BATCH_SIZE)

  # Evaluate model on test dataset.
  eval_input_fn = _make_training_input_fn(
      tf_transform_output,
      os.path.join(working_dir, TRANSFORMED_TEST_DATA_FILEBASE + '*'),
      batch_size=1)

  # Export the model.
  serving_input_fn = _make_serving_input_fn(tf_transform_output)
  exported_model_dir = os.path.join(working_dir, EXPORTED_MODEL_DIR)
  estimator.export_saved_model(exported_model_dir, serving_input_fn)

  return estimator.evaluate(input_fn=eval_input_fn, steps=num_test_instances)
 

把它放在一起

我们已经创建了所有我们需要进行预处理我们的人口普查数据,训练一个模型,并为服务做准备的东西。到目前为止,我们刚刚得到的东西准备好。现在是时候开始运行!

 import tempfile
temp = tempfile.gettempdir()

transform_data(train, test, temp)
results = train_and_evaluate(temp)
pprint.pprint(results)
 
WARNING:apache_beam.runners.interactive.interactive_environment:Dependencies required for Interactive Beam PCollection visualization are not available, please use: `pip install apache-beam[interactive]` to install necessary dependencies to enable all data visualization features.

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow_transform/tf_utils.py:220: Tensor.experimental_ref (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use ref() instead.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow_transform/tf_utils.py:220: Tensor.experimental_ref (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use ref() instead.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/saved_model/signature_def_utils_impl.py:201: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/saved_model/signature_def_utils_impl.py:201: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:No assets to write.

INFO:tensorflow:No assets to write.

Warning:tensorflow:Issue encountered when serializing tft_mapper_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_mapper_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_analyzer_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_analyzer_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/dcabb80023c14178be58171288b007ff/saved_model.pb

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/dcabb80023c14178be58171288b007ff/saved_model.pb

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:No assets to write.

INFO:tensorflow:No assets to write.

Warning:tensorflow:Issue encountered when serializing tft_mapper_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_mapper_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_analyzer_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

Warning:tensorflow:Issue encountered when serializing tft_analyzer_use.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'Counter' object has no attribute 'name'

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/49dab3a217e64749824fc5066de4bf7f/saved_model.pb

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/49dab3a217e64749824fc5066de4bf7f/saved_model.pb

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 

Warning:tensorflow:Tensorflow version (2.2.0) found. Note that Tensorflow Transform support for TF 2.0 is currently in beta, and features such as tf.function may not work as intended. 
WARNING:apache_beam.utils.interactive_utils:Failed to alter the label of a transform with the ipython prompt metadata. Cannot figure out the pipeline that the given pvalueish ((<PCollection[DecodeTestData/ParDo(_MapAndFilterErrorsDoFn).None] at 0x7fe7780bb2b0>, {'_schema': feature {
  name: "age"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "capital-gain"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "capital-loss"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "education"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "education-num"
  type: FLOAT
}
feature {
  name: "hours-per-week"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "label"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "marital-status"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "native-country"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "occupation"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "race"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "relationship"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "sex"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "workclass"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
}), (<PCollection[AnalyzeAndTransformDataset/AnalyzeDataset/CreateSavedModel/BindTensors/ReplaceWithConstants.None] at 0x7fe778158f60>, BeamDatasetMetadata(dataset_metadata={'_schema': feature {
  name: "age"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "capital-gain"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "capital-loss"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "education"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "education-num"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "hours-per-week"
  type: FLOAT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "label"
  type: INT
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "marital-status"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "native-country"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "occupation"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "race"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "relationship"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "sex"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
feature {
  name: "workclass"
  type: BYTES
  presence {
    min_fraction: 1.0
  }
  shape {
  }
}
}, deferred_metadata=<PCollection[AnalyzeAndTransformDataset/AnalyzeDataset/ComputeDeferredMetadata.None] at 0x7fe7780ed7b8>))) belongs to. Thus noop.

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets written to: /tmp/tmpbflj3wnm/tftransform_tmp/94352f4b103a4aeb8a141e3efbaafea3/assets

INFO:tensorflow:Assets written to: /tmp/tmpbflj3wnm/tftransform_tmp/94352f4b103a4aeb8a141e3efbaafea3/assets

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/94352f4b103a4aeb8a141e3efbaafea3/saved_model.pb

INFO:tensorflow:SavedModel written to: /tmp/tmpbflj3wnm/tftransform_tmp/94352f4b103a4aeb8a141e3efbaafea3/saved_model.pb

Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.

Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:vocabulary_size = 9 in workclass is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/workclass.

INFO:tensorflow:vocabulary_size = 9 in workclass is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/workclass.

INFO:tensorflow:vocabulary_size = 16 in education is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/education.

INFO:tensorflow:vocabulary_size = 16 in education is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/education.

INFO:tensorflow:vocabulary_size = 7 in marital-status is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/marital-status.

INFO:tensorflow:vocabulary_size = 7 in marital-status is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/marital-status.

INFO:tensorflow:vocabulary_size = 15 in occupation is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/occupation.

INFO:tensorflow:vocabulary_size = 15 in occupation is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/occupation.

INFO:tensorflow:vocabulary_size = 6 in relationship is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/relationship.

INFO:tensorflow:vocabulary_size = 6 in relationship is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/relationship.

INFO:tensorflow:vocabulary_size = 5 in race is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/race.

INFO:tensorflow:vocabulary_size = 5 in race is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/race.

INFO:tensorflow:vocabulary_size = 2 in sex is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/sex.

INFO:tensorflow:vocabulary_size = 2 in sex is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/sex.

INFO:tensorflow:vocabulary_size = 42 in native-country is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/native-country.

INFO:tensorflow:vocabulary_size = 42 in native-country is inferred from the number of elements in the vocabulary_file /tmp/transform_fn/assets/native-country.

Warning:tensorflow:Using temporary folder as model directory: /tmp/tmp1z2zsfze

Warning:tensorflow:Using temporary folder as model directory: /tmp/tmp1z2zsfze

INFO:tensorflow:Using config: {'_model_dir': '/tmp/tmp1z2zsfze', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}

INFO:tensorflow:Using config: {'_model_dir': '/tmp/tmp1z2zsfze', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:1666: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:1666: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/training/training_util.py:236: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/training/training_util.py:236: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.

INFO:tensorflow:Calling model_fn.

INFO:tensorflow:Calling model_fn.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py:540: Layer.add_variable (from tensorflow.python.keras.engine.base_layer_v1) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `layer.add_weight` method instead.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py:540: Layer.add_variable (from tensorflow.python.keras.engine.base_layer_v1) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `layer.add_weight` method instead.

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/keras/optimizer_v2/ftrl.py:144: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor

Warning:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.6/site-packages/tensorflow/python/keras/optimizer_v2/ftrl.py:144: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Create CheckpointSaverHook.

INFO:tensorflow:Create CheckpointSaverHook.

INFO:tensorflow:Graph was finalized.

INFO:tensorflow:Graph was finalized.

INFO:tensorflow:Running local_init_op.

INFO:tensorflow:Running local_init_op.

INFO:tensorflow:Done running local_init_op.

INFO:tensorflow:Done running local_init_op.

INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 0...

INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 0...

INFO:tensorflow:Saving checkpoints for 0 into /tmp/tmp1z2zsfze/model.ckpt.

INFO:tensorflow:Saving checkpoints for 0 into /tmp/tmp1z2zsfze/model.ckpt.

INFO:tensorflow:Calling checkpoint listeners after saving checkpoint 0...

INFO:tensorflow:Calling checkpoint listeners after saving checkpoint 0...

INFO:tensorflow:loss = 88.72284, step = 0

INFO:tensorflow:loss = 88.72284, step = 0

INFO:tensorflow:global_step/sec: 104.093

INFO:tensorflow:global_step/sec: 104.093

INFO:tensorflow:loss = 43.419994, step = 100 (0.962 sec)

INFO:tensorflow:loss = 43.419994, step = 100 (0.962 sec)

INFO:tensorflow:global_step/sec: 142.387

INFO:tensorflow:global_step/sec: 142.387

INFO:tensorflow:loss = 49.636517, step = 200 (0.702 sec)

INFO:tensorflow:loss = 49.636517, step = 200 (0.702 sec)

INFO:tensorflow:global_step/sec: 143.583

INFO:tensorflow:global_step/sec: 143.583

INFO:tensorflow:loss = 48.2191, step = 300 (0.696 sec)

INFO:tensorflow:loss = 48.2191, step = 300 (0.696 sec)

INFO:tensorflow:global_step/sec: 132.771

INFO:tensorflow:global_step/sec: 132.771

INFO:tensorflow:loss = 43.51023, step = 400 (0.753 sec)

INFO:tensorflow:loss = 43.51023, step = 400 (0.753 sec)

INFO:tensorflow:global_step/sec: 136.735

INFO:tensorflow:global_step/sec: 136.735

INFO:tensorflow:loss = 39.578957, step = 500 (0.731 sec)

INFO:tensorflow:loss = 39.578957, step = 500 (0.731 sec)

INFO:tensorflow:global_step/sec: 141.726

INFO:tensorflow:global_step/sec: 141.726

INFO:tensorflow:loss = 31.377352, step = 600 (0.706 sec)

INFO:tensorflow:loss = 31.377352, step = 600 (0.706 sec)

INFO:tensorflow:global_step/sec: 140.978

INFO:tensorflow:global_step/sec: 140.978

INFO:tensorflow:loss = 43.05789, step = 700 (0.709 sec)

INFO:tensorflow:loss = 43.05789, step = 700 (0.709 sec)

INFO:tensorflow:global_step/sec: 141.092

INFO:tensorflow:global_step/sec: 141.092

INFO:tensorflow:loss = 31.173666, step = 800 (0.709 sec)

INFO:tensorflow:loss = 31.173666, step = 800 (0.709 sec)

INFO:tensorflow:global_step/sec: 140.01

INFO:tensorflow:global_step/sec: 140.01

INFO:tensorflow:loss = 51.318253, step = 900 (0.714 sec)

INFO:tensorflow:loss = 51.318253, step = 900 (0.714 sec)

INFO:tensorflow:global_step/sec: 143.036

INFO:tensorflow:global_step/sec: 143.036

INFO:tensorflow:loss = 44.896477, step = 1000 (0.699 sec)

INFO:tensorflow:loss = 44.896477, step = 1000 (0.699 sec)

INFO:tensorflow:global_step/sec: 142.212

INFO:tensorflow:global_step/sec: 142.212

INFO:tensorflow:loss = 40.37133, step = 1100 (0.703 sec)

INFO:tensorflow:loss = 40.37133, step = 1100 (0.703 sec)

INFO:tensorflow:global_step/sec: 137.841

INFO:tensorflow:global_step/sec: 137.841

INFO:tensorflow:loss = 39.548, step = 1200 (0.726 sec)

INFO:tensorflow:loss = 39.548, step = 1200 (0.726 sec)

INFO:tensorflow:global_step/sec: 140.89

INFO:tensorflow:global_step/sec: 140.89

INFO:tensorflow:loss = 54.550842, step = 1300 (0.710 sec)

INFO:tensorflow:loss = 54.550842, step = 1300 (0.710 sec)

INFO:tensorflow:global_step/sec: 143.092

INFO:tensorflow:global_step/sec: 143.092

INFO:tensorflow:loss = 39.631958, step = 1400 (0.699 sec)

INFO:tensorflow:loss = 39.631958, step = 1400 (0.699 sec)

INFO:tensorflow:global_step/sec: 139.315

INFO:tensorflow:global_step/sec: 139.315

INFO:tensorflow:loss = 49.820618, step = 1500 (0.718 sec)

INFO:tensorflow:loss = 49.820618, step = 1500 (0.718 sec)

INFO:tensorflow:global_step/sec: 139.872

INFO:tensorflow:global_step/sec: 139.872

INFO:tensorflow:loss = 45.730972, step = 1600 (0.715 sec)

INFO:tensorflow:loss = 45.730972, step = 1600 (0.715 sec)

INFO:tensorflow:global_step/sec: 138.04

INFO:tensorflow:global_step/sec: 138.04

INFO:tensorflow:loss = 36.139393, step = 1700 (0.724 sec)

INFO:tensorflow:loss = 36.139393, step = 1700 (0.724 sec)

INFO:tensorflow:global_step/sec: 140.354

INFO:tensorflow:global_step/sec: 140.354

INFO:tensorflow:loss = 40.87008, step = 1800 (0.712 sec)

INFO:tensorflow:loss = 40.87008, step = 1800 (0.712 sec)

INFO:tensorflow:global_step/sec: 142.71

INFO:tensorflow:global_step/sec: 142.71

INFO:tensorflow:loss = 53.13055, step = 1900 (0.701 sec)

INFO:tensorflow:loss = 53.13055, step = 1900 (0.701 sec)

INFO:tensorflow:global_step/sec: 141.784

INFO:tensorflow:global_step/sec: 141.784

INFO:tensorflow:loss = 40.821915, step = 2000 (0.705 sec)

INFO:tensorflow:loss = 40.821915, step = 2000 (0.705 sec)

INFO:tensorflow:global_step/sec: 140.922

INFO:tensorflow:global_step/sec: 140.922

INFO:tensorflow:loss = 48.694305, step = 2100 (0.710 sec)

INFO:tensorflow:loss = 48.694305, step = 2100 (0.710 sec)

INFO:tensorflow:global_step/sec: 142.652

INFO:tensorflow:global_step/sec: 142.652

INFO:tensorflow:loss = 39.659786, step = 2200 (0.701 sec)

INFO:tensorflow:loss = 39.659786, step = 2200 (0.701 sec)

INFO:tensorflow:global_step/sec: 124.202

INFO:tensorflow:global_step/sec: 124.202

INFO:tensorflow:loss = 42.969543, step = 2300 (0.805 sec)

INFO:tensorflow:loss = 42.969543, step = 2300 (0.805 sec)

INFO:tensorflow:global_step/sec: 122.688

INFO:tensorflow:global_step/sec: 122.688

INFO:tensorflow:loss = 38.666878, step = 2400 (0.815 sec)

INFO:tensorflow:loss = 38.666878, step = 2400 (0.815 sec)

INFO:tensorflow:global_step/sec: 121.456

INFO:tensorflow:global_step/sec: 121.456

INFO:tensorflow:loss = 41.72638, step = 2500 (0.824 sec)

INFO:tensorflow:loss = 41.72638, step = 2500 (0.824 sec)

INFO:tensorflow:global_step/sec: 124.748

INFO:tensorflow:global_step/sec: 124.748

INFO:tensorflow:loss = 43.654724, step = 2600 (0.801 sec)

INFO:tensorflow:loss = 43.654724, step = 2600 (0.801 sec)

INFO:tensorflow:global_step/sec: 122.324

INFO:tensorflow:global_step/sec: 122.324

INFO:tensorflow:loss = 31.018797, step = 2700 (0.818 sec)

INFO:tensorflow:loss = 31.018797, step = 2700 (0.818 sec)

INFO:tensorflow:global_step/sec: 125.791

INFO:tensorflow:global_step/sec: 125.791

INFO:tensorflow:loss = 44.809124, step = 2800 (0.795 sec)

INFO:tensorflow:loss = 44.809124, step = 2800 (0.795 sec)

INFO:tensorflow:global_step/sec: 123.229

INFO:tensorflow:global_step/sec: 123.229

INFO:tensorflow:loss = 39.58447, step = 2900 (0.811 sec)

INFO:tensorflow:loss = 39.58447, step = 2900 (0.811 sec)

INFO:tensorflow:global_step/sec: 126.829

INFO:tensorflow:global_step/sec: 126.829

INFO:tensorflow:loss = 55.24282, step = 3000 (0.789 sec)

INFO:tensorflow:loss = 55.24282, step = 3000 (0.789 sec)

INFO:tensorflow:global_step/sec: 123.026

INFO:tensorflow:global_step/sec: 123.026

INFO:tensorflow:loss = 45.018, step = 3100 (0.813 sec)

INFO:tensorflow:loss = 45.018, step = 3100 (0.813 sec)

INFO:tensorflow:global_step/sec: 125.527

INFO:tensorflow:global_step/sec: 125.527

INFO:tensorflow:loss = 32.267475, step = 3200 (0.797 sec)

INFO:tensorflow:loss = 32.267475, step = 3200 (0.797 sec)

INFO:tensorflow:global_step/sec: 125.278

INFO:tensorflow:global_step/sec: 125.278

INFO:tensorflow:loss = 39.706387, step = 3300 (0.799 sec)

INFO:tensorflow:loss = 39.706387, step = 3300 (0.799 sec)

INFO:tensorflow:global_step/sec: 123.954

INFO:tensorflow:global_step/sec: 123.954

INFO:tensorflow:loss = 44.980774, step = 3400 (0.806 sec)

INFO:tensorflow:loss = 44.980774, step = 3400 (0.806 sec)

INFO:tensorflow:global_step/sec: 122.245

INFO:tensorflow:global_step/sec: 122.245

INFO:tensorflow:loss = 34.893124, step = 3500 (0.818 sec)

INFO:tensorflow:loss = 34.893124, step = 3500 (0.818 sec)

INFO:tensorflow:global_step/sec: 142.51

INFO:tensorflow:global_step/sec: 142.51

INFO:tensorflow:loss = 46.19402, step = 3600 (0.701 sec)

INFO:tensorflow:loss = 46.19402, step = 3600 (0.701 sec)

INFO:tensorflow:global_step/sec: 143.921

INFO:tensorflow:global_step/sec: 143.921

INFO:tensorflow:loss = 40.14846, step = 3700 (0.695 sec)

INFO:tensorflow:loss = 40.14846, step = 3700 (0.695 sec)

INFO:tensorflow:global_step/sec: 141.015

INFO:tensorflow:global_step/sec: 141.015

INFO:tensorflow:loss = 39.931377, step = 3800 (0.709 sec)

INFO:tensorflow:loss = 39.931377, step = 3800 (0.709 sec)

INFO:tensorflow:global_step/sec: 139.846

INFO:tensorflow:global_step/sec: 139.846

INFO:tensorflow:loss = 41.347256, step = 3900 (0.716 sec)

INFO:tensorflow:loss = 41.347256, step = 3900 (0.716 sec)

INFO:tensorflow:global_step/sec: 142.112

INFO:tensorflow:global_step/sec: 142.112

INFO:tensorflow:loss = 41.49544, step = 4000 (0.703 sec)

INFO:tensorflow:loss = 41.49544, step = 4000 (0.703 sec)

INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 4071...

INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 4071...

INFO:tensorflow:Saving checkpoints for 4071 into /tmp/tmp1z2zsfze/model.ckpt.

INFO:tensorflow:Saving checkpoints for 4071 into /tmp/tmp1z2zsfze/model.ckpt.

INFO:tensorflow:Calling checkpoint listeners after saving checkpoint 4071...

INFO:tensorflow:Calling checkpoint listeners after saving checkpoint 4071...

INFO:tensorflow:Loss for final step: 48.927376.

INFO:tensorflow:Loss for final step: 48.927376.

Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_3:0\022\tworkclass"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_5:0\022\teducation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_7:0\022\016marital-status"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\013\n\tConst_9:0\022\noccupation"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_11:0\022\014relationship"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_13:0\022\004race"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_15:0\022\003sex"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


Warning:tensorflow:Expected binary or unicode string, got type_url: "type.googleapis.com/tensorflow.AssetFileDef"
value: "\n\014\n\nConst_17:0\022\016native-country"


INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Saver not created because there are no variables in the graph to restore

INFO:tensorflow:Calling model_fn.

INFO:tensorflow:Calling model_fn.

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Signatures INCLUDED in export for Classify: ['serving_default', 'classification']

INFO:tensorflow:Signatures INCLUDED in export for Classify: ['serving_default', 'classification']

INFO:tensorflow:Signatures INCLUDED in export for Regress: ['regression']

INFO:tensorflow:Signatures INCLUDED in export for Regress: ['regression']

INFO:tensorflow:Signatures INCLUDED in export for Predict: ['predict']

INFO:tensorflow:Signatures INCLUDED in export for Predict: ['predict']

INFO:tensorflow:Signatures INCLUDED in export for Train: None

INFO:tensorflow:Signatures INCLUDED in export for Train: None

INFO:tensorflow:Signatures INCLUDED in export for Eval: None

INFO:tensorflow:Signatures INCLUDED in export for Eval: None

INFO:tensorflow:Restoring parameters from /tmp/tmp1z2zsfze/model.ckpt-4071

INFO:tensorflow:Restoring parameters from /tmp/tmp1z2zsfze/model.ckpt-4071

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets added to graph.

INFO:tensorflow:Assets written to: /tmp/exported_model_dir/temp-1595841268/assets

INFO:tensorflow:Assets written to: /tmp/exported_model_dir/temp-1595841268/assets

INFO:tensorflow:SavedModel written to: /tmp/exported_model_dir/temp-1595841268/saved_model.pb

INFO:tensorflow:SavedModel written to: /tmp/exported_model_dir/temp-1595841268/saved_model.pb

INFO:tensorflow:Calling model_fn.

INFO:tensorflow:Calling model_fn.

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Done calling model_fn.

INFO:tensorflow:Starting evaluation at 2020-07-27T09:14:30Z

INFO:tensorflow:Starting evaluation at 2020-07-27T09:14:30Z

INFO:tensorflow:Graph was finalized.

INFO:tensorflow:Graph was finalized.

INFO:tensorflow:Restoring parameters from /tmp/tmp1z2zsfze/model.ckpt-4071

INFO:tensorflow:Restoring parameters from /tmp/tmp1z2zsfze/model.ckpt-4071

INFO:tensorflow:Running local_init_op.

INFO:tensorflow:Running local_init_op.

INFO:tensorflow:Done running local_init_op.

INFO:tensorflow:Done running local_init_op.

INFO:tensorflow:Evaluation [1628/16281]

INFO:tensorflow:Evaluation [1628/16281]

INFO:tensorflow:Evaluation [3256/16281]

INFO:tensorflow:Evaluation [3256/16281]

INFO:tensorflow:Evaluation [4884/16281]

INFO:tensorflow:Evaluation [4884/16281]

INFO:tensorflow:Evaluation [6512/16281]

INFO:tensorflow:Evaluation [6512/16281]

INFO:tensorflow:Evaluation [8140/16281]

INFO:tensorflow:Evaluation [8140/16281]

INFO:tensorflow:Evaluation [9768/16281]

INFO:tensorflow:Evaluation [9768/16281]

INFO:tensorflow:Evaluation [11396/16281]

INFO:tensorflow:Evaluation [11396/16281]

INFO:tensorflow:Evaluation [13024/16281]

INFO:tensorflow:Evaluation [13024/16281]

INFO:tensorflow:Evaluation [14652/16281]

INFO:tensorflow:Evaluation [14652/16281]

INFO:tensorflow:Evaluation [16280/16281]

INFO:tensorflow:Evaluation [16280/16281]

INFO:tensorflow:Evaluation [16281/16281]

INFO:tensorflow:Evaluation [16281/16281]

INFO:tensorflow:Inference Time : 118.49958s

INFO:tensorflow:Inference Time : 118.49958s

INFO:tensorflow:Finished evaluation at 2020-07-27-09:16:29

INFO:tensorflow:Finished evaluation at 2020-07-27-09:16:29

INFO:tensorflow:Saving dict for global step 4071: accuracy = 0.850562, accuracy_baseline = 0.76377374, auc = 0.9016513, auc_precision_recall = 0.96709853, average_loss = 0.3241848, global_step = 4071, label/mean = 0.76377374, loss = 0.3241848, precision = 0.8778903, prediction/mean = 0.7650077, recall = 0.93429834

INFO:tensorflow:Saving dict for global step 4071: accuracy = 0.850562, accuracy_baseline = 0.76377374, auc = 0.9016513, auc_precision_recall = 0.96709853, average_loss = 0.3241848, global_step = 4071, label/mean = 0.76377374, loss = 0.3241848, precision = 0.8778903, prediction/mean = 0.7650077, recall = 0.93429834

INFO:tensorflow:Saving 'checkpoint_path' summary for global step 4071: /tmp/tmp1z2zsfze/model.ckpt-4071

INFO:tensorflow:Saving 'checkpoint_path' summary for global step 4071: /tmp/tmp1z2zsfze/model.ckpt-4071

{'accuracy': 0.850562,
 'accuracy_baseline': 0.76377374,
 'auc': 0.9016513,
 'auc_precision_recall': 0.96709853,
 'average_loss': 0.3241848,
 'global_step': 4071,
 'label/mean': 0.76377374,
 'loss': 0.3241848,
 'precision': 0.8778903,
 'prediction/mean': 0.7650077,
 'recall': 0.93429834}

我们做了什么

在这个例子中我们使用tf.Transform预处理人口普查数据的数据集,和培养用清洗和变换后的数据的模型。我们还建立了一个输入功能,当我们在生产环境中部署我们的训练模型来进行推理,我们可以使用。通过使用相同的代码,训练和推理,我们避免数据偏移的问题。一路上,我们了解了创建一个Apache梁变换来执行,我们需要清洁的数据转换,包裹我们的TensorFlow数据FeatureColumns 。这仅仅是一小片TensorFlow变换可以做什么!我们鼓励你潜入tf.Transform和发现什么可以为你做什么。