我正在尝试创建一个识别面部的模型。但我一直遇到这个错误,其他类似问题的答案都没有解决这个问题。代码如下:
X = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
Y = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
X_test = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
Y_test = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
# Input is a 250x250 image with 3 color channels (red, green and blue)
network = input_data(shape=[None, 250, 250, 3],
data_preprocessing=img_prep,
data_augmentation=img_aug)
# Step 1: Convolution
network = conv_2d(network, 32, 3, activation='relu')
# Step 2: Max pooling
network = max_pool_2d(network, 2)
# Step 3: Convolution again
network = conv_2d(network, 64, 3, activation='relu')
# Step 4: Convolution yet again
network = conv_2d(network, 64, 3, activation='relu')
# Step 5: Max pooling again
network = max_pool_2d(network, 2)
# Step 6: Fully-connected 512 node neural network
network = fully_connected(network, 512, activation='relu')
# Step 7: Dropout - throw away some data randomly during training to prevent over-fitting
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')
# Tell tflearn how we want to train the network
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='faceRecog.tfl.ckpt')
# Train it! We'll do 100 training passes and monitor it as it goes.
model.fit(X, Y, n_epoch=10, shuffle=True, validation_set=(X_test, Y_test),
show_metric=True, batch_size=10,
snapshot_epoch=True,
run_id='faceRecog')
我一直在
ValueError:无法为Tensor' TargetsData / Y:0'提供形状值(10,250,250,3),它具有形状'(?,2)' 。
此时我已尝试过所有内容,并且无法完全理解如何解决问题。
答案 0 :(得分:1)
您的输入形状为(?, 250, 250, 3)
(基于开头的注释以及您之前使用卷云层的事实),您的输出形状为(?, 2)
(基于快速你的最后一层是一个完全连接的层,有2个输出神经元)。然而,您将相同的数据集提供给两者:
X = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
Y = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
^^请注意,您为X
和Y
加载了相同的文件。
由于我不知道你想要达到的目标,因此有两种可能的解决方案:
如果您正在尝试构建某种类型的自动编码器(在这种情况下,将相同的数据集输入到输入和输出都是有意义的),您需要更改网络的体系结构,即卷积层应该进入反卷积层。如何做到超出了单个Stack Overflow答案的范围
如果您正在尝试构建某种分类器,那么您就不会为Y
读取正确的文件。 Y
应包含您要预测的标签,而不是图片。