2016-09-27 3 views
1

내 데이터 집합의 TensorFlow에서 wide_n_deep_tutorial 프로그램을 실행하는 동안 다음 오류가 표시됩니다. 어떤 도움에 감사드립니다TypeError : 서명이 일치하지 않습니다. 키는 dtype <dtype : 'string'>이어야합니다. <dtype : 'int64'>

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])) 

: 다음

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

enter image description here

는 코드입니다.

답변

0

이 오류가 처리 된 부분을 확인하기 위해 오류 메시지보다 먼저 출력을 보는 데 도움이되지만 메시지는 정수가 대신 문자열이 될 것으로 예상됩니다. . 나는 단지 추측하고 있지만이 인스턴스에서 참조 된 키가 될 수 있으므로 스크립트의 초기 부분에서 올바르게 설정 한 열 이름입니까?

0

판단하는 것은 input_fn의 결과물을 입력하여 발생한 문제입니다. your traceback으로 판단하십시오. 귀하의 스파 스 텐서는 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} 
관련 문제