yx131
yx131

Reputation: 127

Tensorflow Notfound Error

I am using Spyder (Python 3.5). The tensorflow version is 1.8.0. I was trying to implement a deep neural network using the tf.estimator.DNNClassifier method.However, I encountered this error, which is listed as follows. The codes are pasted as the following. I am not sure what is wrong here. Thank you so much for your help.

Error: NotFoundError (see above for traceback): Key dnn/hiddenlayer_0/bias not found in checkpoint [[Node: 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"]

Upvotes: 2

Views: 344

Answers (1)

f4.
f4.

Reputation: 3852

You probably have checkpoint files for an old version or your model.

Clear the output folder and re-run your script.

P.S.: I ran it on my machine and it works fine

Upvotes: 1

Related Questions