我一直在尝试使用TFLearn训练数据集来实现卷积神经网络。 我有一个10类的数据集,图像大小为64 * 32,3个输入通道和2个输出,即检测到/未检测到图像。
这是我的代码。
# Load the data set
def read_data():
with open("deep_logo.pickle", 'rb') as f:
save = pickle.load(f)
X = save['train_dataset']
Y = save['train_labels']
X_test = save['test_dataset']
Y_test = save['test_labels']
del save
return [X, X_test], [Y, Y_test]
def reformat(dataset, labels):
dataset = dataset.reshape((-1, 64, 32,3)).astype(np.float32)
labels = (np.arange(10) == labels[:, None]).astype(np.float32)
return dataset, labels
dataset, labels = read_data()
X,Y = reformat(dataset[0], labels[0])
X_test, Y_test = reformat(dataset[2], labels[2])
print('Training set', X.shape, Y.shape)
print('Test set', X_test.shape, Y_test.shape)
#building convolutional layers
network = input_data(shape=[None, 64, 32, 3],data_preprocessing=img_prep,
data_augmentation=img_aug)
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 64, 3, activation='relu')
network = conv_2d(network, 128, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
# Step 8: Fully-connected neural network with two outputs to make the final
prediction
network = fully_connected(network, 2, activation='softmax')
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=0.001)
# Wrap the network in a model object
model = tflearn.DNN(network, tensorboard_verbose=0, checkpoint_path='logo-
classifier.tfl.ckpt')
# Training it . 100 training passes and monitor it as it goes.
model.fit(X,Y, n_epoch=100, shuffle=True, validation_set=(X_test, Y_test),
show_metric=True, batch_size=64,
snapshot_epoch=True,
run_id='logo-classifier')
# Save model when training is complete to a file
model.save("logo-classifier.tfl")
print("Network trained and saved as logo-classifier.tfl!")
我收到以下错误
ValueError:无法为Tensor'TargetsData / Y:0'提供形状值(64,10),其形状为'(?,2)'
我有X和X_test包含图像参数,Y和Y_test包含pickle文件中的labeles。我尝试过类似问题的解决方案,但这对我没用。
任何帮助都会被暗示。
感谢。
答案 0 :(得分:1)
您正在收到该错误,因为您正在喂食的形状与张量流所期望的形状之间存在不匹配。要解决此问题,您可能需要将当前形状为(64,10)的Y重新整形为(?,2)。例如,您将执行以下操作:
Y = np.reshape(Y, (-1, 2))
答案 1 :(得分:0)
您已将输出张量形状指定为(?,2),并且您的标签的形状为(?,10)。您的标签和输出张量形状必须相同。