Tensorflow找不到错误

时间:2018-06-25 13:54:17

标签: python tensorflow deep-learning

我正在使用Spyder(Python 3.5)。张量流版本为1.8.0。我试图使用tf.estimator.DNNClassifier方法实现深层神经网络,但是遇到此错误,其列出如下。代码粘贴如下。我不确定这里出什么问题了。非常感谢你的帮助。

错误:NotFoundError(请参阅上面的回溯):在检查点中未找到键dnn / hiddenlayer_0 / bias      [[[节点:保存/还原V2 =还原V2 [dtypes = [DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT,...,DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_INT64]] /本地主机:/ device = / job任务:0 /设备:CPU:0“](_ arg_save / Const_0_0,保存/还原V2 / tensor_names,保存/还原V2 / shape_and_slices)]] p

import tensorflow as tf
import numpy as np
from sklearn.datasets import load_iris
from sklearn.cross_validation import train_test_split
#from sklearn.metrics import classification_report, confusion_matrix

# Data sets
iris = load_iris()
X =np.float32(iris['data']) 
y = iris['target']
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)

# Specify that all features have real-value data
feature_columns = [tf.feature_column.numeric_column("x", shape=[4])]

# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns,
                                            hidden_units=[8, 20, 10],
                                            n_classes=3,
                                            model_dir="./output")

# Define the Training datasets 
train_input_fn = tf.estimator.inputs.numpy_input_fn(
        x = {"x": np.array(X_train)},
        y = np.array(y_train),
        num_epochs = None, 
        shuffle = True) 

# Define the test datasets .
test_input_fn = tf.estimator.inputs.numpy_input_fn(
      x={"x": np.array(X_test)},
      y=np.array(y_test),
      num_epochs=1,
      shuffle=False)

# Fit model.
classifier.train(input_fn = train_input_fn, steps=2000)
accuracy_score = classifier.evaluate(input_fn=test_input_fn)["accuracy"]

1 个答案:

答案 0 :(得分:1)

您可能具有旧版本或模型的检查点文件。

清除output文件夹并重新运行脚本。

P.S .:我在计算机上运行了它,并且工作正常