tensorflow / transform

Input pipeline framework
Apache License 2.0
984 stars 214 forks source link

Example export using build_raw_serving_input_receiver_fn #156

Closed schmidt-jake closed 4 years ago

schmidt-jake commented 4 years ago

All the export examples usebuild_parsing_serving_input_receiver_fn. Is there a best practice for using build_raw_serving_input_receiver_fn? Since tf.placeholder is deprecated, the only thing I've found that works to specify the receiver tensors is tf.keras.Input...

def build_serving_input_receiver_fn(tft_output, raw_feature_spec):
        def serving_input_fn():
            raw_input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn({k: tf.keras.Input(name=k, shape=v.shape, dtype=v.dtype) for k, v in raw_feature_spec.items() if k in feature_keys}, default_batch_size=None)
            serving_input_receiver = raw_input_fn()
            raw_features = serving_input_receiver.features
            transformed_features = tft_output.transform_raw_features(raw_features, True)
            return tf.estimator.export.ServingInputReceiver(transformed_features, serving_input_receiver.receiver_tensors)
        return serving_input_fn
zoyahav commented 4 years ago

For now (before native Keras support) we still suggest using Placeholders, or tf.keras.Inputs. Placeholders are still available in TF 2.x using tf.compat.v1.Placeholder.

niczky12 commented 4 years ago

For anyone looking to do this with placeholders, note that it's placeholder with lowercase p: tf.compat.v1.placeholder