一开始,我需要说我使用的是TF v 1.1 .
代码:
import random
import tensorflow as tf
xData = []
yData = []
for _ in range(10000):
x = random.random()
xData.append(x)
y = 2 * x
yData.append(y)
xc = tf.contrib.layers.real_valued_column("")
estimator = tf.contrib.learn.DynamicRnnEstimator(problem_type = constants.ProblemType.LINEAR_REGRESSION,
prediction_type = PredictionType.SINGLE_VALUE,
sequence_feature_columns = [xc],
context_feature_columns = None,
num_units = 5,
cell_type = 'lstm',
optimizer = 'SGD',
learning_rate = '0.1')
def get_train_inputs():
x = tf.constant(xData)
y = tf.constant(yData)
return x, y
estimator.fit(input_fn=get_train_inputs, steps=TRAINING_STEPS)
我有:
AttributeError:'Tensor'对象没有属性'get'
这里 . 相同的代码适用于LinearRegressor而不是DynamicRnnEstimator .
警告:tensorflow:来自E:\ Python35 \ lib \ site-packages \ tensorflow \ contrib \ learn \ python \ learn \ estimators \ dynamic_rnn_estimator.py:724:regression_target(来自tensorflow.contrib.layers.python.layers.target_column)已弃用,将于2016-11-12之后删除 . 更新说明:此文件将在弃用日期后删除 . 请切换到third_party / tensorflow / contrib / learn / python / learn / estimators / head.py警告:tensorflow:使用临时文件夹作为模型目录:C:\ Users \ pavel \ AppData \ Local \ Temp \ tmpzy68t_iw Blockquote Traceback(最近一次调用最后一次):文件“C:/Users/pavel/PycharmProjects/rnnEstimator/main.py”,第31行,在estimator.fit中(input_fn = get_train_inputs,steps = 1000)文件“E:\ Python35 \ lib \ site-packages \ tensorflow \ python \ util \ deprecation.py”,第281行,在new_func中返回func(* args,** kwargs)文件“E:\ Python35 \ lib \ site-packages \ tensorflow \ contrib \ learn \ python \ learn \ estimators \ estimator.py“,第430行,在fit loss = self._train_model(input_fn = input_fn,hooks = hooks)文件”E:\ Python35 \ lib \ site -packages \ tensorflow \ contrib \ learn \ python \ learn \ estimators \ estimator.py“,第927行,在_train_model中model_fn_ops = self._get_train_ops(features,labels)文件”E:\ Python35 \ lib \ site-packages \ tensorflow \的contrib \学习\ python的\学习\ê stimators \ estimator.py“,第1132行,在_get_train_ops中返回self._call_model_fn(features,labels,model_fn_lib.ModeKeys.TRAIN)文件”E:\ Python35 \ lib \ site-packages \ tensorflow \ contrib \ learn \ python \ learn \ estimators \ estimator.py“,第1103行,在_call_model_fn中model_fn_results = self._model_fn(features,labels,** kwargs)文件”E:\ Python35 \ lib \ site-packages \ tensorflow \ contrib \ learn \ python \ learn \ estimators \ dynamic_rnn_estimator.py“,第516行,_dynamic_rnn_model_fn sequence_length = features.get(sequence_length_key)AttributeError:'Tensor'对象没有属性'get'
1 回答