我遇到TFLearn/TensorFlow的一些問題。我已經調整了我的np.reshape到合適的尺寸,但我與錯誤而崩潰:ValueError:無法提供形狀的值TensorFlow
這個錯誤發生在訓練代碼行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有關嗎?我不確定。
所以你有一個數據集有2個類,大小爲48?你可以在這裏發佈一個Y值的樣本嗎? –
錯誤說'Y'沒有預期的形狀。 –