Python TensorFlow-形状与存储在检查点中的形状不匹配

Python TensorFlow-形状与存储在检查点中的形状不匹配,python,tensorflow,Python,Tensorflow,我对TensorFlow非常陌生,我正在尝试对我的数据使用简单的神经网络。 我有一个.csv数据,有19列,最后一列是目标列。它是0或1 我从这里开始尝试修改以适应我的数据。我制作了这个 ... # Data sets IRIS_TRAINING = "Training.csv" IRIS_TEST = "Test.csv" def main(): # Load datasets. training_set = tf.contrib.

我对TensorFlow非常陌生,我正在尝试对我的数据使用简单的神经网络。 我有一个.csv数据,有19列,最后一列是目标列。它是0或1

我从这里开始尝试修改以适应我的数据。我制作了这个

...

    # 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()
我只是改变了隐藏单位,使其成为1层,并改变了形状为18,因为我有18个特点。然而,我得到了这个错误

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

我相信您的问题在于
tf.estimator.DNNClassifier()中的
model\u dir=“/tmp/iris\u model”
。这实际上是加载并重新训练第一次使用Tensorflow示例数据运行时保存到该目录中的模型。只需取出
model\u dir=“/tmp/iris\u model”
部分,错误就会消失


来源:

我相信你的问题在于
tf.estimator.DNNClassifier()中的
model\u dir=“/tmp/iris\u model”
。这实际上是加载并重新训练第一次使用Tensorflow示例数据运行时保存到该目录中的模型。只需取出
model\u dir=“/tmp/iris\u model”
部分,错误就会消失

资料来源: