代码之家  ›  专栏  ›  技术社区  ›  Glen

Keras和TensorFlow:我得到了一个无效的辩论

  •  0
  • Glen  · 技术社区  · 6 年前

    我刚开始学习Keras和TensorFlow,我已经开始学习教程了( https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/ )

    不幸的是,当我运行完成的代码(我正在使用Anaconda-不确定这是否相关)时,我得到以下错误:

    代码如下:

    # Create your first MLP in Keras
    from keras.models import Sequential
    from keras.layers import Dense
    import numpy
    # fix random seed for reproducibility
    numpy.random.seed(7)
    # load pima indians dataset
    dataset = numpy.loadtxt("D:\Applications\Python Apps\pima-indians-diabetes.csv", delimiter=",")
    # split into input (X) and output (Y) variables
    X = dataset[:,0:8]
    Y = dataset[:,8]
    # create model
    model = Sequential()
    model.add(Dense(12, input_dim=8, activation='relu'))
    model.add(Dense(8, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    # Fit the model
    model.fit(X, Y, epochs=150, batch_size=10)
    # evaluate the model
    scores = model.evaluate(X, Y)
    print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
    

    错误如下:

    InvalidArgumentError: Input to reshape is a tensor with 10 values, but the requested shape has 0
    [[Node: training/Adam/gradients/loss/dense_3_loss/Mean_1_grad/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _class=["loc:@training/Adam/gradients/loss/dense_3_loss/Mean_1_grad/truediv"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](training/Adam/gradients/loss/dense_3_loss/mul_grad/Sum, training/Adam/gradients/loss/dense_3_loss/Mean_1_grad/DynamicStitch/_75)]]
    

    这是一个整体的图像,更容易阅读- https://i.imgur.com/ZTd3ZeT.jpg

    如果有人能帮我,我会非常感激。

    谢谢 格伦

    1 回复  |  直到 6 年前
        1
  •  0
  •   Glen    6 年前

    这是TensorFlow 1.09版的一个bug。移动到1.10修复它