【问题标题】:Tensorflow Notfound ErrorTensorFlow 未找到错误
【发布时间】:2018-12-04 03:07:47
【问题描述】:

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

错误:NotFoundError(参见上文的追溯):检查点中未找到密钥 dnn/hiddenlayer_0/bias [[节点:save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT64], _device="/job:localhost/replica:0/ task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

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"]

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

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

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

    P.S.:我在我的机器上运行了它,它工作正常

    【讨论】:

    • 我清除了输出文件夹,问题解决了。
    猜你喜欢
    • 1970-01-01
    • 2019-09-24
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多