训练时无法解决张量流中的'unsupported callable'

时间:2020-06-22 15:40:03

标签: python tensorflow

我一直在尝试使用张量流完成线性回归算法,但是我一直收到这个错误,即train()函数使用了不受支持的可调用对象。我一直在Windows 10计算机上使用google colab。这是错误消息:

TypeError                                 Traceback (most recent call last)
/usr/lib/python3.6/inspect.py in getfullargspec(func)
   1125                                        skip_bound_arg=False,
-> 1126                                        sigcls=Signature)
   1127     except Exception as ex:

9 frames
TypeError: <TextLineDatasetV2 shapes: (), types: tf.string> is not a callable object

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/usr/lib/python3.6/inspect.py in getfullargspec(func)
   1130         # else. So to be fully backwards compatible, we catch all
   1131         # possible exceptions here, and reraise a TypeError.
-> 1132         raise TypeError('unsupported callable') from ex
   1133 
   1134     args = []

TypeError: unsupported callable

这是代码:

#Imports
import tensorflow as tf
import pandas as pd
from IPython.display import clear_output

#Data Extraction for only certain attributes to make things easier
xset = pd.read_csv('student-mat.csv', sep = ';')
xtrain = xset[['G1', 'G2', 'G3', 'studytime', 'activities']]
xtrain.to_csv('student-matedu.csv')
xtrain.to_csv(sep = ';')

#Feature Columns as fc
fc = []
catg = ['studytime', 'activities']
for key in catg:
  uv = xtrain[key].unique()
  fc.append(tf.feature_column.categorical_column_with_vocabulary_list(key, uv))
numg = ['G1', 'G2', 'G3']
for key2 in numg:
  fc.append(tf.feature_column.numeric_column(key2))

#training set
ds = tf.data.TextLineDataset('student-matedu.csv')
ds.shuffle(150)
ds.batch(25)
ds.repeat(5)

#Testing set:
estimator = tf.estimator.LinearClassifier(fc)
dftest = pd.read_csv('student-por.csv', sep=';')
dftest = dftest[['G1', 'G2', 'G3', 'studytime', 'activities']]
dftest.to_csv('testset.csv')
dstest = tf.data.TextLineDataset('testset.csv')
dstest.shuffle(1)
dstest.batch(1)
dstest.repeat(1)
estimator.train(ds)
clear_output()
print('result')

0 个答案:

没有答案