我在使用TFLearn / TensorFlow时遇到了一些问题。我已将我的np.reshape调整为适当的大小,但是因为错误而崩溃:
此错误发生在培训代码的第17行:
ValueError: Cannot feed value of shape (48, 1) for Tensor 'TargetsData/Y:0', which has shape '(?, 2)'
参考线:
model.fit(X, Y, n_epoch=250, validation_set=(W,Z), show_metric=True)
我的培训代码如下:
import deepneuralnet as net
import numpy as np
from tflearn.data_utils import image_preloader
import os
model = net.model
train_path = os.path.abspath('train')
print(train_path)
X, Y = image_preloader(target_path=train_path, image_shape=(100, 100),
mode='folder', grayscale=False, categorical_labels=True, normalize=True)
X = np.reshape(X, (-1, 100, 100, 3))
validate_path = os.path.abspath('validate')
W, Z = image_preloader(target_path=validate_path, image_shape=(100, 100),
mode='folder', grayscale=False, categorical_labels=True, normalize=True)
W = np.reshape(W, (-1, 100, 100, 3))
model.fit(X, Y, n_epoch=250, validation_set=(W,Z), show_metric=True)
model.save('./ZtrainedNet/final-model.tfl')
神经网络是:
import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression
from tflearn.metrics import Accuracy
acc = Accuracy()
network = input_data(shape=[None, 100, 100, 3])
# Conv layers ------------------------------------
network = conv_2d(network, 64, 3, strides=1, activation='relu')
network = max_pool_2d(network, 2, strides=2)
network = conv_2d(network, 64, 3, strides=1, activation='relu')
network = max_pool_2d(network, 2, strides=2)
network = conv_2d(network, 64, 3, strides=1, activation='relu')
network = conv_2d(network, 64, 3, strides=1, activation='relu')
network = conv_2d(network, 64, 3, strides=1, activation='relu')
network = max_pool_2d(network, 2, strides=2)
# Fully Connected Layers -------------------------
network = fully_connected(network, 1024, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 1024, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 2, activation='softmax')
network = regression(network, optimizer='momentum',
loss='categorical_crossentropy',
learning_rate=0.001, metric=acc)
model = tflearn.DNN(network)
我的理解是它与softmax有关吗?我不确定。
答案 0 :(得分:0)
您的Y值是否也是单热编码的?我只是想猜测为什么Y是形状(?,2)。 如果您可以在训练集中分享一些样本标签,那就太好了。
答案 1 :(得分:0)
原来,子文件夹搞砸了。 2对应于我拥有的子文件夹的数量,我认为我设置正确,但内部只有1个子文件夹" train。"