2016-09-27 10 views
1

私のデータセットのTensorFlowからwide_n_deep_tutorialプログラムを実行すると、次のエラーが表示されます。TypeError:シグネチャが一致しません。キーはdtype <dtype: 'string'>である必要があります。<dtype: 'int64'>

"TypeError: Signature mismatch. Keys must be dtype <dtype: 'string'>, got <dtype:'int64'>" 

enter image description here

次のコードスニペットです:

def input_fn(df): 
    """Input builder function.""" 
    # Creates a dictionary mapping from each continuous feature column name (k) to 
    # the values of that column stored in a constant Tensor. 
    continuous_cols = {k: tf.constant(df[k].values) for k in CONTINUOUS_COLUMNS} 
    # Creates a dictionary mapping from each categorical feature column name (k) 
    # to the values of that column stored in a tf.SparseTensor. 
    categorical_cols = {k: tf.SparseTensor(
     indices=[[i, 0] for i in range(df[k].size)], 
     values=df[k].values, 
     shape=[df[k].size, 1]) 
         for k in CATEGORICAL_COLUMNS} 

    # Merges the two dictionaries into one. 
    feature_cols = dict(continuous_cols) 
    feature_cols.update(categorical_cols) 
    # Converts the label column into a constant Tensor. 
    label = tf.constant(df[LABEL_COLUMN].values) 
    # Returns the feature columns and the label. 

    return feature_cols, label 



def train_and_eval(): 
    """Train and evaluate the model.""" 
    train_file_name, test_file_name = maybe_download() 

    df_train=train_file_name 
    df_test=test_file_name 

    df_train[LABEL_COLUMN] = (
     df_train["impression_flag"].apply(lambda x: "generated" in x)).astype(str) 

    df_test[LABEL_COLUMN] = (
     df_test["impression_flag"].apply(lambda x: "generated" in x)).astype(str) 

    model_dir = tempfile.mkdtemp() if not FLAGS.model_dir else FLAGS.model_dir 
    print("model directory = %s" % model_dir) 

    m = build_estimator(model_dir) 
    print('model succesfully build!') 
    m.fit(input_fn=lambda: input_fn(df_train), steps=FLAGS.train_steps) 
    print('model fitted!!') 
    results = m.evaluate(input_fn=lambda: input_fn(df_test), steps=1) 
    for key in sorted(results): 
    print("%s: %s" % (key, results[key])) 

すべてのヘルプは高く評価されます。

答えて

0

このエラーが処理されたプロセスの部分を特定するために、エラーメッセージの前の出力を確認するのに役立ちますが、メッセージは文字列であると予想されます。私は推測しているだけですが、このインスタンスで参照されているキーになる可能性があるため、スクリプトの前の部分で列名が正しく設定されていますか?

0

あなたの問題は、フィーチャーの列への入力やinput_fnの出力が原因です。あなたのスパーステンソルは、valuesパラメータの非文字列dtypを供給される可能性が最も高いです。スパースフィーチャ列には文字列値が必要です。正しいデータが入力されていることを確認してください。確信がある場合は、次の方法を試してみてください。

categorical_cols = {k: tf.SparseTensor(
    indices=[[i, 0] for i in range(df[k].size)], 
    values=df[k].astype(str).values, # Convert sparse values to string type 
    shape=[df[k].size, 1]) 
        for k in CATEGORICAL_COLUMNS} 
関連する問題