我正在使用keras创建一个卷积神经网络,试图将图像分为两个不同的类,并且由于某种原因,在第一个时代之后,准确性永远不会改变.
使用Keras之后to_categorical()我的标签看起来像:
[[0. 1.]
[1. 0.]
[1. 0.]
[0. 1.]]
Run Code Online (Sandbox Code Playgroud)
我的模型的代码是:
model = Sequential()
model.add(Conv2D(filters=32, kernel_size=[5, 5], strides=1, padding='same', activation='relu', input_shape=(imageSize, imageSize, 3)))
model.add(MaxPooling2D())
model.add(Conv2D(filters=64, kernel_size=[5, 5], strides=1, padding='same', activation='relu'))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(2))
sgd = SGD() # Use stochastic gradient descent for now
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.summary()
counter = 0
# Train one cycle at a time so we can shuffle data inbetween
for x in range(trainingEpochs):
counter += 1
print() # New line
print('Epoch ' + str(counter)) …Run Code Online (Sandbox Code Playgroud)