![](/img/trans.png)
[英]Tflearn, AxlexNet, ValueError: Cannot feed value of shape (64, 277, 277, 3) for Tensor u'InputData/X:0', which has shape '(?, 227, 227, 3)'
[英]Python Tflearn - ValueError: Cannot feed value of shape (16, 1) for Tensor u'InputData/X:0', which has shape '(?, 2)'
作为机器学习和tflearn / tensorflow的新手,我试图遵循tflearn(泰坦尼克号)的快速入门教程。
修改它以满足我的需要,我得到了以下代码:
from __future__ import print_function
import numpy as np
import tflearn
# Load CSV file, indicate that the first column represents labels
from tflearn.data_utils import load_csv
data, labels = load_csv('nowcastScaled.csv', target_column=1, n_classes=2)
# Preprocessing function
def preprocess(data):
return np.array(data, dtype=np.float32)
# Preprocess data
data = preprocess(data)
# Build neural network
net = tflearn.input_data(shape=[None, 2])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
loss='categorical_crossentropy')
# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)
但是我得到了这个错误:
ValueError:无法为形状为'(?,2)'的Tensor u'InputData / X:0'输入形状(16,1)的值
我的csv文件由2列组成,一列是索引(条目数,因为这只是我将自己的测试限制在100个条目之内的测试),另一列是拥塞分数(我要预测的范围是0到200),都是数值。
我有点理解我正在尝试为它提供一个不好的值(或者至少是他没有等待的东西),但是我看不出如何纠正它。
添加
data = np.reshape(data, (-1, 2))
更正了我的问题,但是给了我同样的错误,但是这次是Y,所以我做到了:
labels = np.reshape(labels, (-1, 2))
无论是在回归之前,还是看起来都成功了。 我不知道这是最好的方法,还是最好的方法,但现在我设法解决了这个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.