繁体   English   中英

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

[英]TensorFlow - shape does not match the shape stored in checkpoint

我是TensorFlow的新手,我正在尝试对数据进行简单神经网络。 我有19列的.csv数据,最后一列是目标列。 它是0或1。

我从这里https://www.tensorflow.org/get_started/estimator开始,并尝试进行修改以适合我的数据。 我制作了这个。

...

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

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

来源: https : //www.tensorflow.org/api_docs/python/tf/estimator/DNNClassifier

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM