簡體   English   中英

Keras和TensorFlow:我收到一個InvalidArgumentError

[英]Keras and TensorFlow: I'm getting an InvalidArgumentError

我剛開始使用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

如果有人能夠提供幫助,我將非常感激。

謝謝格倫

這是TensorFlow 1.09版中的錯誤。 移至1.10已修復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM