Keras和TensorFlow:我收到一个InvalidArgumentError

时间:2018-09-20 11:31:04

标签: python tensorflow keras anaconda

我刚开始使用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 个答案:

答案 0 :(得分:0)

这是TensorFlow 1.09版中的错误。移至1.10即可解决