【发布时间】:2017-02-25 19:36:51
【问题描述】:
使用 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
...其中 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 的初学者,不知道该怎么做。
【问题讨论】:
-
在
tflearn.regression中你试过设置to_one_hot=True, n_classes=2吗? -
这给了我 ValueError: Cannot feed value of shape (7, 2) for Tensor 'TargetsData/Y:0', which has shape '(?,)'
标签: python-3.x tensorflow