无论我改变什么,dense_1_input
总是想要#(无,296)'。错误是:
ValueError: Error when checking model input: expected dense_1_input to have shape (None, 296) but got array with shape (296, 1) `
代码:
from keras.models import Sequential
from keras.layers import Dense
from random import randrange
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
def myGenerator():
# load pima indians dataset
dataset = numpy.genfromtxt("vectorFile.csv", delimiter=",")
# split into input (X) and output (Y) variables
global X
global Y
X = dataset[:,0:148]
Y = dataset[:,149]
size = len(X)
while 1:
outputData = []
outputAnswer = []
for i in range(1):
firstPick = randrange(0,size)
firstResult = Y[firstPick]
firstPlayer = X[firstPick][0]
while True:
secondPick = randrange(0,size)
if firstPlayer==X[secondPick][0]:
break
if Y[firstPick]>Y[secondPick]:
outputAnswer.append([1,0])
else:
outputAnswer.append([0,1])
result = numpy.concatenate((X[firstPick], X[secondPick]))
result.reshape(1, 296)
outputData.append(result)
yield outputData,outputAnswer
# create model
model = Sequential()
model.add(Dense(12, input_shape=(296, ), activation='relu'))
#model.add(Dense(12, input_dim=296, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(2, 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)
#samples_per_epoch = batch_size * number_of_batches
#samples_per_epoch = 100 * 1000
model.fit_generator(myGenerator(), steps_per_epoch=5)
# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
答案 0 :(得分:1)
以这种方式更改myGenerator()
功能:
result = result.reshape(1, 296)
因此,重塑运算符的结果将被保存。