【发布时间】:2019-12-26 11:05:25
【问题描述】:
我正在研究使用 keras 的分类系统。 Keras 通过检查哪个是最大的数字来对标签进行分类。 例如,如果输出是 [0.1 0.8 0.1],它会将标签 1 归类为正确答案,因为它是 0.8,这是最高的数字。
但是在二进制分类中我得到了这个结果。
[0.642]
[0.996]
[0.976]
[0.302]
[0.963]
[0.115]
.
.
.
我认为 Keras 将它们分类为: 如果结果[i][0] > 0.5 返回 1
但这只是我的猜测,所以我想知道 Keras 是如何对二进制结果进行分类的。
这是我使用的代码。
model = Sequential()
# Step 1 - Convolution
model.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
# Step 2 - Pooling
model.add(MaxPooling2D(pool_size = (2, 2)))
# Adding a second convolutional layer
model.add(Conv2D(32, (3, 3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
# Step 3 - Flattening
model.add(Flatten())
# Step 4 - Full connection
model.add(Dense(units = 128, activation = 'relu'))
model.add(Dense(units = 1, activation = 'sigmoid'))
import numpy as np
print("-- Predict --")
output = model.predict_generator(test_set, steps=5)
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
print(test_set.class_indices)
print(output)
【问题讨论】:
-
你的模型和优化目标是什么?