张量流无法找到训练模型

时间:2017-07-22 21:06:58

标签: python tensorflow

我正在尝试训练模型,但我收到了这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 289, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 543, in evaluate
    log_progress=log_progress)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 816, in _evaluate_model
    % self._model_dir)
tensorflow.contrib.learn.python.learn.estimators._sklearn.NotFittedError: Couldn't find trained model at /var/folders/hd/96gvrtvn66dcnbntwn9v3skh0000gp/T/tmpq4Q43n.

这是我的代码:

data = pandas.read_csv(data_file,sep=";",names=header)
CONTINUOUS_COLUMNS = ['rsi','stochk','stochd']
CATEGORICAL_COLUMNS = []

def input_fn(df):
  # Creates a dictionary mapping from each continuous feature column name (k) to
  # the values of that column stored in a constant Tensor.
  continuous_cols = {k: tf.constant(df[k].values)
                     for k in CONTINUOUS_COLUMNS}
  # Creates a dictionary mapping from each categorical feature column name (k)
  # to the values of that column stored in a tf.SparseTensor.
  categorical_cols = {k: tf.SparseTensor(
      indices=[[i, 0] for i in range(df[k].size)],
      values=df[k].values,
      dense_shape=[df[k].size, 1])
                      for k in CATEGORICAL_COLUMNS}
  # Merges the two dictionaries into one.
  feature_cols = dict(continuous_cols.items() + categorical_cols.items())
  # Converts the label column into a constant Tensor.
  label = tf.constant(df[LABEL_COLUMN].values)
  # Returns the feature columns and the label.
  return feature_cols, label


def train_input_fn():
  return input_fn(df_train)

def eval_input_fn():
  return input_fn(df_test)

model_dir = tempfile.mkdtemp()


CONTINUOUS_COLUMNS = ['rsi','stochk','stochd']

### defining the model
m = tf.contrib.learn.LinearClassifier(feature_columns=[
        data['rsi'],
        data['stochk'],
        data['stochd']

    ],
  model_dir=model_dir)


m.fit(input_fn=train_input_fn, steps=200)

results = m.evaluate(input_fn=eval_input_fn, steps=1)

当我检查文件夹时: 的/ var /文件夹/ HD / 96gvrtvn66dcnbntwn9v3skh0000gp / T / tmpq4Q43n

那里没有档案。 但我正在关注这个tutorial并且我没有得到如何在tmp目录中创建文件。

我该如何解决这个问题?

修改

train_input_fn()的输出

train_input_fn()
({'stochd': <tf.Tensor 'Const_10:0' shape=(177144,) dtype=float64>, 'rsi': <tf.Tensor 'Const_8:0' shape=(177144,) dtype=float64>, 'stochk': <tf.Tensor 'Const_9:0' shape=(177144,) dtype=float64>}, <tf.Tensor 'Const_11:0' shape=(177144,) dtype=string>)

0 个答案:

没有答案
相关问题