Dalam panduan TF tentang menyimpan model terdapat paragraf tentang serve_input_receiver_fn yang membahas tentang penerapan fungsi untuk prapemrosesan logika. Saya mencoba melakukan normalisasi data masukan untuk DNNRegressor. Kode mereka untuk fungsinya terlihat seperti ini:
feature_spec = {'foo': tf.FixedLenFeature(...),
'bar': tf.VarLenFeature(...)}
def serving_input_receiver_fn():
"""An input receiver that expects a serialized tf.Example."""
serialized_tf_example = tf.placeholder(dtype=tf.string,
shape=[default_batch_size],
name='input_example_tensor')
receiver_tensors = {'examples': serialized_tf_example}
features = tf.parse_example(serialized_tf_example, feature_spec)
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
Kode saya terlihat seperti ini:
feat_cols = [
tf.feature_column.numeric_column(key="FEATURE1"),
tf.feature_column.numeric_column(key="FEATURE2")
]
def serving_input_receiver_fn():
feature_spec = tf.feature_column.make_parse_example_spec(feat_cols)
default_batch_size = 1
serialized_tf_example = tf.placeholder(dtype=tf.string, shape=[default_batch_size], name='tf_example')
receiver_tensors = { 'examples': serialized_tf_example}
features = tf.parse_example(serialized_tf_example, feature_spec)
fn_norm1 = lamba FEATURE1: normalize_input_data('FEATURE1', FEATURE1)
fn_norm2 = lamba FEATURE2: normalize_input_data('FEATURE2', FEATURE2)
features['FEATURE1'] = tf.map_fn(fn_norm1, features['FEATURE1'], dtype=tf.float32)
features['FEATURE2'] = tf.map_fn(fn_norm2, features['FEATURE2'], dtype=tf.float32)
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
Setelah semua itu, model yang disimpan tidak memiliki fitur saya di grafik. Saya mencoba mencari tahu cara kerjanya jika Anda memiliki lebih dari satu fitur yang ingin Anda lewati.
Saya membuat contoh menggunakan data keras MPG. Terletak di sini:
receiver_tensors
didefinisikan? - person Siyuan Ren   schedule 18.01.2019receiver_tensors
sebagai dict dengan fitur yang ditentukan. Kode tidak error tetapi ketika saya hendak menyajikannya muncul kesalahan yang mengatakan bahwa saya perlu memberikan nilai untuk tf_example. - person Geoff Craig   schedule 18.01.2019tf.Example
, tetapi memisahkan 'Silinder', 'Perpindahan', ... tensor? - person Siyuan Ren   schedule 23.01.2019{ "signature_name": "predict", "instances":[{ "Cylinders": [4.0], "Displacement": [140.0], "Horsepower": [86.0], "Weight": [2790.0], "Acceleration": [15.6], "Model_Year": [82.0], "USA": [1.0], "Europe": [0.0], "Japan": [0.0] }] }
- person Geoff Craig   schedule 23.01.2019{ "error": "Failed to process element: 0 key: Cylinders of \'instances\' list. Error: Invalid argument: JSON object: does not have named input: Cylinders" }
Saya berasumsi bahwa saya salah membangun fungsi input penyajian atau saya perlu mengubah payload JSON. Aku hanya tidak tahu yang mana. Akan sangat membantu jika ada contoh end to end, menurut saya siapa pun yang melayani regressor harus melakukan ini. - person Geoff Craig   schedule 23.01.2019