I have been trying to train a dataset using TFLearn to implement a convolutional neural network. I have a dataset of 10 classes with image size is 64*32, 3 channels of input and 2 outputs i.e image detected/not detected.
我一直在尝试用TFLearn来训练一个数据集来实现卷积神经网络。我有一个10个类的数据集,图像大小是64*32,3个输入通道和2个输出I。e图像检测/检测。
Here is my code.
这是我的代码。
# 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!")
I get the following error
我得到了下面的错误。
ValueError: Cannot feed value of shape (64, 10) for Tensor 'TargetsData/Y:0', which has shape '(?, 2)'
ValueError:无法为张量“TargetsData/Y:0”提供形状的值(64,10),它的形状是(?2)'
I have X and X_test with parameters of images and Y and Y_test with labeles in the pickle file. I have tried solutions from similar question, but the didn't work for me.
我有X和X_test参数的图像和Y和Y_test与labeles在pickle文件。我尝试过类似的问题,但对我不起作用。
Any help would be appericiated.
任何帮助都将被接受。
Thanks.
谢谢。
2 个解决方案
#1
1
You are getting that error because there is a mismatch between the shape of what you are feeding and what the tensorflow is expecting. To fix the issue, you might want to reshape your Y which is currently shaped at (64,10) to (?, 2). For example, you would do the following:
你会得到这个错误,因为你所吃的东西的形状和你所期望的东西之间不匹配。为了解决这个问题,你可能想要重塑你的Y,它目前的形状是(64,10)到(?,例如,你会做以下工作:
Y = np.reshape(Y, (-1, 2))
#2
0
Youve specified your output tensor shape as (?,2) and your labels is of the shape (?,10). Your label and output tensor shape must be the same.
您已经指定了输出张量形状为(?,2),您的标签是形状(?,10)。你的标签和输出张量的形状必须相同。
#1
1
You are getting that error because there is a mismatch between the shape of what you are feeding and what the tensorflow is expecting. To fix the issue, you might want to reshape your Y which is currently shaped at (64,10) to (?, 2). For example, you would do the following:
你会得到这个错误,因为你所吃的东西的形状和你所期望的东西之间不匹配。为了解决这个问题,你可能想要重塑你的Y,它目前的形状是(64,10)到(?,例如,你会做以下工作:
Y = np.reshape(Y, (-1, 2))
#2
0
Youve specified your output tensor shape as (?,2) and your labels is of the shape (?,10). Your label and output tensor shape must be the same.
您已经指定了输出张量形状为(?,2),您的标签是形状(?,10)。你的标签和输出张量的形状必须相同。