尝试将’n’转换为张量但失败了。错误:不支持None值

我在这上面已经深陷其中,无法让这个(看似)简单的线性回归工作。我知道答案可能就在眼前,但我觉得我已经盯着它太久了,看不到了 :).

回溯信息:

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.

代码: https://pastebin.com/M9arSCQa

数据文件: https://storage.googleapis.com/stackquestion2/201701.csv

更新在应用了一些建议后,错误已经改变了,然而,这个错误是我在发帖前就遇到过的,这意味着我在原地打转 🙂

这是完整的错误信息:

tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_0_enqueue_input/fifo_queue' is closed and has insufficient elements (requested 128, current size 0)     [[Node: fifo_queue_DequeueUpTo = QueueDequeueUpToV2[component_types=[DT_INT64, DT_STRING, DT_STRING, DT_DOUBLE, DT_STRING, ..., DT_STRING, DT_STRING, DT_STRING, DT_FLOAT, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](enqueue_input/fifo_queue, fifo_queue_DequeueUpTo/n)]]

最新代码: https://pastebin.com/TvCw0rVw


回答:

我认为你的问题出在这里,

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时,它会检查该参数。只要删除batch_size或将其设置为训练数据集大小的因数即可

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注