Python keras每次都返回相同的结果

Python keras每次都返回相同的结果,python,tensorflow,keras,Python,Tensorflow,Keras,我正在努力使用我的第一个tensorflow代码。我想确定这幅画中的哪个是苹果还是梨。但它返回的值与苹果的值相同,尽管这张图片显然是梨。代码工作时没有错误。如何修改它 x= np.array(x) y = np.array(y) x_train, x_test, y_train, y_test = \ train_test_split(x, y) xy = (x_train, x_test, y_train, y_test) np.save('C:train.npy',xy) x_

我正在努力使用我的第一个tensorflow代码。我想确定这幅画中的哪个是苹果还是梨。但它返回的值与苹果的值相同,尽管这张图片显然是梨。代码工作时没有错误。如何修改它

x= np.array(x)
y = np.array(y)

x_train, x_test, y_train, y_test = \
    train_test_split(x, y)
xy = (x_train, x_test, y_train, y_test)

np.save('C:train.npy',xy)

x_train, x_test, y_train, y_test = np.load('train.npy',allow_pickle=True)

x_train = x_train.astype('float') / 256
x_test = x_test.astype('float') /256


model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=x_train.shape[1:], padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))

model.add(Conv2D(64, (3, 3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

# 전결합층
model.add(Flatten())    # 벡터형태로 reshape
model.add(Dense(512))   # 출력
model.add(Activation('relu'))
model.add(Dropout(0.5))

model.add(Dense(2))
model.add(Activation('sigmoid'))
# 모델 구축하기
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])

hdf5_file = "7obj-model.hdf5"
if os.path.exists(hdf5_file):
    model.load_weights(hdf5_file)
else:
    model.fit(x_train, y_train, batch_size=32, nb_epoch=10)
    model.save_weights(hdf5_file)

score = model.evaluate(x_test, y_test)
print('loss = ', score[0])
print('accuracy = ', score[1])

代替上一个
model.add(密集(2))
尝试
model.add(密集(1))
。然后确保
y\u列
y\u测试
(n,1)
大小的数组