首页 文章

谷歌colab中的Tensorflow估算器错误

提问于
浏览
0

我正在google colab环境中训练一个DNN的tensorflow,这段代码一直运行到昨天,但现在当我运行我的代码的估算器训练部分时,它会出错 .

我不改变它 . 似乎这个问题存在于其他代码中,例如stanford的示例代码形式之前没有任何错误,https://colab.research.google.com/drive/1nG7Ga46jrWF5n7pHe0FK6anB0pLNgBVt

但现在当你运行该部分时:

estimator.train(input_fn=train_input_fn, steps=1000);

它给出了与我相同的错误:

> **TypeError                                 Traceback (most recent call last)
> /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py
> in make_tensor_proto(values, dtype, shape, verify_shape)**
> 
> **TypeError: Expected binary or unicode string, got {'sent_symbol': <tf.Tensor 'random_shuffle_queue_DequeueMany:3' shape=(128,)
> dtype=int64>}**
> 
> **TypeError                                 Traceback (most recent call last) <ipython-input-10-9dfe23a4bf62> in <module>()
> ----> 1 estimator.train(input_fn=train_input_fn, steps=1000);**
> 
> **TypeError: Failed to convert object of type <class 'dict'> to Tensor. Contents: {'sent_symbol': <tf.Tensor
> 'random_shuffle_queue_DequeueMany:3' shape=(128,) dtype=int64>}.
> Consider casting elements to a supported type.**

1 回答

  • 0

    方法 tf.estimator.inputs.pandas_input_fny 属性接收输入Pandas Series 对象 .

    要从DataFrame中提取目标'sent_symbol',请调用 training_labels['sent_symbol'] .

    要修复此脚本,请按如下所示修改代码:

    # Training input on the whole training set with no limit on training epochs.
    train_input_fn = tf.estimator.inputs.pandas_input_fn(
        training_examples, training_labels['sent_symbol'], num_epochs=None, shuffle=True)
    
    # Prediction on the whole training set.
    predict_train_input_fn = tf.estimator.inputs.pandas_input_fn(
        training_examples, training_labels['sent_symbol'], shuffle=False)
    # Prediction on the test set.
    predict_test_input_fn = tf.estimator.inputs.pandas_input_fn(
        validation_examples, validation_labels['sent_symbol'], shuffle=False)
    

相关问题