我一直在嘗試使用TFLearn來訓練數據集實現卷積神經網絡。 我有一個10級的數據集,圖像大小爲64 * 32,3個通道的輸入和2個輸出,即圖像檢測/未檢測。TensorFlow/TFLearn:ValueError:無法爲張量u'target/Y:0'提供shape(64,10)的值,其形狀爲'(?,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: Cannot feed value of shape (64, 10) for Tensor 'TargetsData/Y:0', which has shape '(?, 2)'
我有X和X_test用圖像和Y Y_test的參數與泡菜文件labeles。我已經嘗試了類似問題的解決方案,但是這對我並不適用。
任何幫助將被appericiated。
謝謝。