在DNNClassifier中将list或ndarray作为feature_column传递

时间:2018-04-30 17:17:45

标签: tensorflow-estimator

func textFieldCharacterTypeLimit(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    let allowedCharacters = CharacterSet.decimalDigits
    let characterSet = CharacterSet(charactersIn: string)
    return allowedCharacters.isSuperset(of: characterSet)
}

我得到的错误是

import tensorflow as tf
import pandas as pd


a = [[1,1],[2,2],[3,3]]
b = [11,22,33]

mydata = pd.DataFrame({'images':a,'labels':b})
feature_columns = [tf.feature_column.numeric_column('images',shape=[1,1])]


train_input_fn = tf.estimator.inputs.pandas_input_fn(x =mydata,
                                                 y=mydata['labels'],
                                                 batch_size=60,
                                                 num_epochs=1,
                                                 shuffle=True)


estimator = tf.estimator.DNNClassifier(hidden_units=[64,32,16],
                                   feature_columns=feature_columns,
                                   n_classes=2)


estimator.train(input_fn=train_input_fn,steps=100)

读取多个stackoverflow页面和github ...它必须对INFO:tensorflow:Create CheckpointSaverHook. INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InternalError'>, Unable to get element as bytes. INFO:tensorflow:Saving checkpoints for 0 into /tmp/tmptver1w_k/model.ckpt. TypeError Traceback (most recent call last) TypeError: expected bytes, list found 执行某些操作。但无法弄明白。

请帮忙。

1 个答案:

答案 0 :(得分:0)

TF Estimator期望字节作为x的输入。

试试这个,它应该让你通过这个错误:

a = [bytes([1,1]), bytes([2,2]), bytes([3,3])]