【发布时间】:2018-04-15 03:41:24
【问题描述】:
我已经根据一些天气数据训练了一个深度神经网络回归器。当我尝试分类器.predict() 时,它返回一个生成器对象。通常我们所做的是将 list() 放在对象上以获取预测。
它曾经可以工作,但我相信在最近的更新之后,它不再工作了。我目前使用的是 tensorflow 1.7.0。我尝试降级到多个版本的 tensorflow,但找不到一个有效的版本。
import tensorflow as tf
feature_columns = [tf.feature_column.numeric_column("x", shape=[163])]
classifier = tf.estimator.DNNRegressor(feature_columns=feature_columns,
hidden_units=[200,100,20],
model_dir='model/'
)
onehot,price=load_single_data([[5,18,16,1],'Mostly Sunny','Mostly Sunny',46.5])
prediction= classifier.predict(np.array(onehot))
#This line produced the error
print(list(prediction))
产生的错误是:
Traceback (most recent call last):
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 1089, in getfullargspec
sigcls=Signature)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 2156, in _signature_from_callable
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: array([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0]) is not a callable object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/5V/PycharmProjects/UberAPI/deep_learning.py", line 41, in <module>
print(list(prediction))
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 486, in predict
input_fn, model_fn_lib.ModeKeys.PREDICT)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 662, in _get_features_from_input_fn
result = self._call_input_fn(input_fn, mode)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 763, in _call_input_fn
input_fn_args = util.fn_args(input_fn)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\util.py", line 55, in fn_args
args = tf_inspect.getfullargspec(fn).args
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\util\tf_inspect.py", line 67, in getfullargspec
if d.decorator_argspec is not None), spec_fn(target))
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 1095, in getfullargspec
raise TypeError('unsupported callable') from ex
TypeError: unsupported callable
这样做会产生:
print(prediction)
>> <generator object Estimator.predict at 0x00000069E3AC0BF8>
好的,这是一个完整的回溯
Traceback (most recent call last):
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 1089, in getfullargspec
sigcls=Signature)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 2156, in _signature_from_callable
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: array([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0]) is not a callable object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/5V/PycharmProjects/UberAPI/deep_learning.py", line 41, in <module>
print(list(prediction))
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 486, in predict
input_fn, model_fn_lib.ModeKeys.PREDICT)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 662, in _get_features_from_input_fn
result = self._call_input_fn(input_fn, mode)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 763, in _call_input_fn
input_fn_args = util.fn_args(input_fn)
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\estimator\util.py", line 55, in fn_args
args = tf_inspect.getfullargspec(fn).args
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\util\tf_inspect.py", line 67, in getfullargspec
if d.decorator_argspec is not None), spec_fn(target))
File "C:\Users\5V\AppData\Local\Programs\Python\Python35\lib\inspect.py", line 1095, in getfullargspec
raise TypeError('unsupported callable') from ex
TypeError: unsupported callable
【问题讨论】:
-
在我看来,问题在于
np.array(onehot)不是正确的input_fn。你确定这对你有用吗?能否提供完整的 Traceback?
标签: python tensorflow machine-learning deep-learning generator