gpt4 book ai didi

python tflearn - 张量 'TargetsData/Y:0' 的 ValueError : Cannot feed value of shape (10, 250, 250, 3) ,其形状为 '(?, 2)'

转载 作者:行者123 更新时间:2023-11-30 09:52:41 24 4
gpt4 key购买 nike

我正在尝试创建一个模型来识别面孔。但我一直遇到这个错误,并且类似问题的其他答案都没有解决这个特定问题。代码如下:

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: Cannot feed value of shape (10, 250, 250, 3) for Tensor 'TargetsData/Y:0', which has shape '(?, 2)'.

此时我已经尝试了所有方法,但无法完全理解如何解决问题。

最佳答案

您的输入形状为 (?, 250, 250, 3) (基于开头的注释以及您早期使用卷积层的事实),您的输出形状为(?, 2) (基于最后一层是具有 2 个输出神经元的全连接层的速度)。然而,您向两者提供相同的数据集:

X = pickle.load(open('dataset.pkl', 'rb')).astype('float32')
Y = pickle.load(open('dataset.pkl', 'rb')).astype('float32')

^^ 请注意,您为 XY 加载相同的文件。

由于我不知道您想要实现什么目标,因此有两种可能的解决方案:

  1. 如果您正在尝试构建某种类型的自动编码器(在这种情况下,将相同的数据集提供给输入和输出是有意义的),您需要更改网络的架构,即卷积层应该输入反卷积层。如何做到这一点超出了单个 Stack Overflow 答案的范围

  2. 如果您尝试构建某种分类器,那么您没有读取 Y 的正确文件。 Y 应包含您尝试预测的标签,而不是图像。

关于python tflearn - 张量 'TargetsData/Y:0' 的 ValueError : Cannot feed value of shape (10, 250, 250, 3) ,其形状为 '(?, 2)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42032429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com