Reputation: 2245
I am very new to TensorFlow and I am trying Simple Neural Network on my data. I have a .csv data with 19 columns and the last column being the target column. It is 0 or 1.
I started from here https://www.tensorflow.org/get_started/estimator and trying to modify to suit my data. I produced this.
...
# Data sets
IRIS_TRAINING = "Training.csv"
IRIS_TEST = "Test.csv"
def main():
# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv_without_header(
filename=IRIS_TRAINING,
target_dtype=np.int,
features_dtype=np.float32)
test_set = tf.contrib.learn.datasets.base.load_csv_without_header(
filename=IRIS_TEST,
target_dtype=np.int,
features_dtype=np.float32)
# Specify that all features have real-value data
feature_columns = [tf.feature_column.numeric_column("x", shape=[18])]
**# SOMETHING WRONG HERE**
classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns,
hidden_units=[18],
n_classes=2,
model_dir="/tmp/iris_model")
# Define the training inputs
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": np.array(training_set.data)},
y=np.array(training_set.target),
num_epochs=None,
shuffle=True)
# Train model.
classifier.train(input_fn=train_input_fn, steps=2000)
# Define the test inputs
test_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": np.array(test_set.data)},
y=np.array(test_set.target),
num_epochs=1,
shuffle=False)
# Evaluate accuracy.
accuracy_score = classifier.evaluate(input_fn=test_input_fn)["accuracy"]
print("\nTest Accuracy: {0:f}\n".format(accuracy_score))
if __name__ == "__main__":
main()
I just changed the hidden units to make it 1 layer and changed the shape to 18 because I have 18 features. However, I am getting this error.
InvalidArgumentError (see above for traceback): tensor_name = dnn/hiddenlayer_0/bias/t_0/Adagrad; shape in shape_and_slice spec [18] does not match the shape stored in checkpoint: [10]
[[Node: save/RestoreV2_1 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_1/tensor_names, save/RestoreV2_1/shape_and_slices)]]
Upvotes: 1
Views: 3022
Reputation: 66
I believe that you problem lies in model_dir="/tmp/iris_model"
in tf.estimator.DNNClassifier()
. This is actually loading and retraining the model that it saved to that directory the first time you ran it with the Tensorflow example data. Just take out the model_dir="/tmp/iris_model"
part and that error should disappear.
Source: https://www.tensorflow.org/api_docs/python/tf/estimator/DNNClassifier
Upvotes: 4