使用tflearn,我正在尝试对图像进行分类。
我的代码是
import tflearn
dataset_file = 'my_dataset.txt'
X, Y = tflearn.data_utils.image_preloader(dataset_file, image_shape=(128, 128),categorical_labels=True, mode='file', grayscale=True, normalize=True)
net = tflearn.input_data(shape=(128,128))
net = tflearn.fully_connected(net, 2, activation='linear')
net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')
model = tflearn.DNN(net, tensorboard_verbose=3)
model.fit(X, Y)
print(model.predict(X))数据集文件如下:
1.jpg 1
2.jpg 1
3.jpg 1
4.jpg 1
5.jpg 0
6.jpg 0
7.jpg 0...where 1和0是图像的类别。
然而,我的预测并不是我所期望的:
[[2.9711711406707764, -3.049826145172119], [9.435855865478516, -11.466367721557617], [-3.7774205207824707, -4.090094089508057], [-7.006657600402832, -3.4418578147888184], [-18.654706954956055, -0.9354709982872009], [-17.237045288085938, -3.1278553009033203], [-18.066274642944336, -1.6454157829284668]]我希望看到图像类型1或0的匹配项。只是tflearn的初学者,不知道该怎么做。
发布于 2016-10-19 13:26:08
尝试更改fully_connected图层以使用'softmax'激活
net = tflearn.fully_connected(net, 2, activation='softmax')现在,您应该可以获得表单的输出:
predictions = [[0.999962568283081, 3.739727253559977e-05],
[0.999962568283081, 3.739727253559977e-05],
...]这里的predictions[i][j]是测试集中的ith元素具有类j的概率。你会注意到所有i的sum(predictions[i]) == 1.0
https://stackoverflow.com/questions/40075883
复制相似问题