Tensorflow 试图转换';n';一个张量,失败了。错误:不支持任何值

Tensorflow 试图转换';n';一个张量,失败了。错误:不支持任何值,tensorflow,machine-learning,Tensorflow,Machine Learning,我已经达到了我的深度,但似乎无法让这个(看起来)简单的线性回归工作。我知道答案可能就在我面前,但我想我已经盯着这个看了很久了:) 回溯: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper preferred_dtype=d

我已经达到了我的深度,但似乎无法让这个(看起来)简单的线性回归工作。我知道答案可能就在我面前,但我想我已经盯着这个看了很久了:)

回溯:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 233, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 401, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 524, in _apply_op_helper
    values, as_ref=input_arg.is_ref).dtype.name
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 233, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 401, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "flights.py", line 143, in <module>
    regressor.train(input_fn=training_input_fn, steps=10000)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 314, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 740, in _train_model
    input_fn, model_fn_lib.ModeKeys.TRAIN))
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 603, in _get_features_and_labels_from_input_fn
    result = self._call_input_fn(input_fn, mode)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 694, in _call_input_fn
    return input_fn(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/inputs/pandas_io.py", line 110, in input_fn
    features = queue.dequeue_many(batch_size)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/data_flow_ops.py", line 475, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 2445, in _queue_dequeue_many_v2
    component_types=component_types, timeout_ms=timeout_ms, name=name)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 528, in _apply_op_helper
    (input_name, err))
ValueError: Tried to convert 'n' to a tensor and failed. Error: None values not supported.

最新代码:

我想你的问题在这里

training_input_fn = tf.estimator.inputs.pandas_input_fn(x=training_data, y=training_label, batch_size=None, shuffle=True, num_epochs=None)

您将batch_size设置为None,这将验证默认参数(128),当它到达deque时,将检查该参数。只需删除批次大小或将其设置为火车大小的一个系数,从外观上看,您的数据源在行中有“Null”条目,如第331行、第373行等。当您在pandas中读取文件时,它会将其转换为
NaN
,但我看不到您替换这些值。因此,据我所知,它们被提前传递为
None
。当然,从高层次的角度来看,这似乎是正确的。因此,尝试类似于
df.fillna(“,inplace=True)
的方法可能会解决问题?我应该提到,这是我在调试时采取的故障排除步骤之一。我一定是从我上传的源代码中删除了它。无论如何,我尝试用fillna填充所有none值,但它似乎根本没有改变错误。这是我在调试时采取的另一个故障排除步骤,将批大小设置为64或128会返回相同的错误:“tensorflow.python.framework.errors\u impl.InternalError:无法以字节形式获取元素”完整的PaSSBIN:你可以检查和运行一个例子,只是为了确保你不是数据集是正确的,至少我们可以删除假设数据集不是在你的数据集的问题检查,第331, 376377行有一些空的细胞,我认为你也应该考虑使用FINA(在数字的情况下使用零)不幸的是,掷骰子。。。填充所有零,将数据限制为5行,并返回原始错误:“tensorflow.python.framework.errors\u impl.InternalError:无法将元素作为字节获取。”这是一个已更改代码的粘贴箱,因此此错误
ValueError:尝试将“n”转换为张量,但失败。错误:不支持的无值
不再存在,是吗?如果是,是否可以提供完整的错误消息?
training_input_fn = tf.estimator.inputs.pandas_input_fn(x=training_data, y=training_label, batch_size=None, shuffle=True, num_epochs=None)