use*_*785 16 python deep-learning tensorflow
我一直在尝试使用tflearn和我自己的数据集执行回归.
使用tflearn我一直在尝试使用MNIST数据集实现基于示例的卷积网络.我没有使用MNIST数据集,而是尝试用我自己的数据替换训练和测试数据.我的数据是从csv文件中读取的,与MNIST数据的形状不同.我有255个功能,代表15*15网格和目标值.在示例中,我将行替换为24-30(并包含import numpy as np):
#read in train and test csv's where there are 255 features (15*15) and a target
csvTrain = np.genfromtxt('train.csv', delimiter=",")
X = np.array(csvTrain[:, :225]) #225, 15
Y = csvTrain[:,225]
csvTest = np.genfromtxt('test.csv', delimiter=",")
testX = np.array(csvTest[:, :225])
testY = csvTest[:,225]
#reshape features for each instance in to 15*15, targets are just a single number
X = X.reshape([-1,15,15,1])
testX = testX.reshape([-1,15,15,1])
## Building convolutional network
network = input_data(shape=[None, 15, 15, 1], name='input')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError:无法为Tensor u'target/Y:0'提供shape(64,)的值,其形状为'(?,10)'
我尝试了各种组合,并在stackoverflow中看到了类似的问题,但没有成功.此页面中的示例对我不起作用并引发类似错误,我不理解提供的答案或类似问题提供的答案.
我如何使用自己的数据?
Oli*_*rot 31
在的线41 MNIST例如,还必须在输出尺寸改变10到1 network = fully_connected(network, 10, activation='softmax')
到network = fully_connected(network, 1, activation='linear')
.请注意,您可以删除最终的softmax.
看你的代码,看来你有一个目标值Y
,这意味着使用L2损失与mean_square
(你会发现这里提供的所有损失):
regression(network, optimizer='adam', learning_rate=0.01,
loss='mean_square', name='target')
Run Code Online (Sandbox Code Playgroud)
此外,重塑Y和Y_test以具有形状(batch_size,1).
以下是如何分析错误:
Cannot feed value ... for Tensor 'target/Y'
,这意味着它来自feed_dict参数Y.of shape (64,)
而网络期望形状(?, 10)
.
fully_connected(network, 10, activation='softmax')
返回大小为10的输出fully_connected(network, 1, activation='linear')
最后,它不是一个错误,而是一个错误的模型架构.