需要帮助以指定csv文件的serving_input_receiver_fn()

时间:2019-07-16 00:17:55

标签: tensorflow deployment classification saving-data

如果我的输入是来自csv文件的数据,如何指定serving_input_receiver_fn()的形状?

您好,我正在尝试使用带有Tensorflow的DNNClassifier估计器进行分类问题。我的输入都是数字密集张量。我需要提供csv文件作为资源来推断该模型。如何为serving_input_receiver_fn()指定输入?

Here is the code snippet:

spend_category = df_new[['Spending_Category']]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(df_new, spend_category,
                                                    stratify=spend_category,
                                                    test_size=0.2,
                                                    random_state=1)

which_measure = tf.feature_column.numeric_column('Which_Measure')
document_type = tf.feature_column.numeric_column('Document_Type')
document_type_group = tf.feature_column.numeric_column('Document_Type_Group')

feature_columns = [which_measure,
                   document_type,
                   document_type_group]

def train_input_fn():
    dataset = tf.data.Dataset.from_tensor_slices((dict(X_train), y_train))
    dataset = dataset.shuffle(1000).repeat().batch(10)
    return dataset

def eval_input_fn():
    dataset = tf.data.Dataset.from_tensor_slices((dict(X_test), y_test))
    return dataset.shuffle(1000).repeat().batch(10)

optimizer_adam = tf.train.AdamOptimizer(learning_rate=0.1)
model = tf.estimator.DNNClassifier([1000, 1000, 500, 100, 50, 10],
                                   feature_columns=feature_columns,
                                   optimizer=optimizer_adam,
                                   n_classes=3)
model.train(input_fn=lambda: train_input_fn(), steps=2000)
eval_results = model.evaluate(input_fn=eval_input_fn, steps=1)

0 个答案:

没有答案